首页 > 解决方案 > 如何使用 Formly 将复选框值保存为字符串?

问题描述

我目前正在使用 Formly 来生成复选框。勾选复选框时,该值将保存为 true,但我需要将其保存为类似“true”的字符串。我还使用 JSON 来生成复选框,这使得操作 HTML 值变得更加困难。

请参阅此示例:https ://stackblitz.com/edit/angular-formly-checkbox?file=src%2Fapp%2Fapp.component.html

有没有办法将值作为字符串而不是布尔值?

标签: angulartypescriptngx-formly

解决方案


您可以获得一组真实值:对于刚刚设置type arrayinsidetemplateOptions

 templateOptions: {
     type: 'array',
     // other options
 }


推荐阅读