来自资源默认值的AngularJS和ng-options
发布时间:2020-12-17 17:45:05 所属栏目:安全 来源:网络整理
导读:目前,我通过在 angularjs中设置ng-options的默认值来实现目标. 有人能帮助我吗? 我从资源中获取选项. select id="customer_country" ng-model="customer.country" ng-options="country.name for country in countries" style="width:230px;"/select 我目前
目前,我通过在
angularjs中设置ng-options的默认值来实现目标.
有人能帮助我吗? 我从资源中获取选项. <select id="customer_country" ng-model="customer.country" ng-options="country.name for country in countries" style="width:230px;"> </select> 我目前的解决方法是设置默认值,如下所示: $scope.countries = Country.query(function() { $scope.customer.country = $scope.countries[0]; }); 但我不认为这是最好的方法. 目前我需要它,它没有空值.有时它也不会有空值,它不应该使用模型中的值来更新模型. 解决方法
我自己遇到了同样的问题,我相信这是最好的解决方法.这也是他们在
documentation for the ng-options directive中完成的方式.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |