来自资源默认值的AngularJS和ng-options

前端之家收集整理的这篇文章主要介绍了来自资源默认值的AngularJS和ng-options前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
目前,我通过在 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中完成的方式.

猜你在找的Angularjs相关文章