为什么 toString() 在 ng-model 属性中不起作用?

Why toString() is not working in ng-model attribute?

如何在 angularjs

中对 ng-model 属性使用 toString()

我的控制器有一个 array 变量

喜欢

$scope.UserNameList = ['a','b','c'];

我想将这个数组绑定到字符串


我试过下面的代码,它是有效的:-

$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 in ng-model attribute?

ng-model 用于双向数据绑定,您无法合理地绑定到函数调用的结果。

如果您只想显示结果,请改用ng-bind