【发布时间】:2016-09-13 21:56:31
【问题描述】:
所以,我有以下工作代码:
角度:
$scope.audit = {user: ''};
HTML:
<md-select ng-model="audit.user"">
<md-option ng-repeat="u in users" value="{{u.username}}">
{{u.username}}
</md-option>
</md-select>
但是,之前我尝试如下绑定。
角度:
$scope.auditUser = '';
HTML:
<md-select ng-model="auditUser">
..
</md-select>
我在网上阅读了一些关于不绑定到 ng-repeat 中的原语的信息,但没有任何结论。所以我想知道为什么后一种解决方案不起作用,为什么在使用 ng-repeat 时我们必须将模型绑定到对象,这是否与 $scope 和 $digest 循环有关(我不知道很详细)?
谢谢
【问题讨论】:
-
你可以试试
ng-options。 -
只是想知道 - ng-value="u.username" 可能会更好。
标签: javascript angularjs angularjs-ng-repeat angular-ngmodel