如何在 angularjs
中的 ng-model 属性上使用 toString()
我的 Controller 有一个数组
变量
喜欢
$scope.UserNameList = ['a','b','c'];
我想将此数组绑定(bind)到字符串
<小时/>我已经尝试过以下有效的代码:-
$scope.UserNameList.toString();//result is a,b,c
但是当我在 ng-model
属性中使用 toString()
时,它不起作用
<td style="text-align: center"><label ng-model="UserNameList.toString()"></label></td>// Does not working
但是如果我使用{{ListOfRoleName.toString()}}
,那么它就可以工作。
<td style="text-align: center">{{ListOfRoleName.toString()}}</td>//Working
Why
toString()
is not working inng-model
attribute?
最佳答案
ng-model
用于双向数据绑定(bind),您无法合理地绑定(bind)到函数调用的结果。
如果您只想显示结果,请使用ng-bind
。
关于javascript - 为什么 toString() 在 ng-model 属性中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30247781/