我有我的复选框输入,它根据变量动态设置"true"值,该变量trueVal是一个字符串.
<input ng-model="foo" ng-true-value="'{{trueVal}}'">
Run Code Online (Sandbox Code Playgroud)
例如,对于trueVal = "something",foo === "something"当复选框被选中.
除了在trueVal等于带有单引号的字符串的情况下,这种方法有效:Customer didn't understand.在这种情况下,有一个错误:
错误:[$ parse:lexerr] Lexer错误:表达式['客户不理解']中第27-28行[']的未终止引用.
我无法删除单引号,因为字符串应按原样设置foo.
更广泛的背景:
我正在根据options我从后端获得的列表创建一组复选框:
<div ng-repeat="(key,option) in options">
<input type="checkbox"
ng-model="foo[key]"
ng-true-value="'{{option.trueVal}}'"
ng-false-value="null">
</div>
Run Code Online (Sandbox Code Playgroud)
所以,给定:
options = {
0: {trueVal: "Customer was late"},
1: {trueVal: "Customer didn't understand"}
};
Run Code Online (Sandbox Code Playgroud)
我希望看到:
foo = {
1: "Customer didn't understand"
};
Run Code Online (Sandbox Code Playgroud)
如果选中第二个框.
angularjs ×1