Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs ng模型不使用ng repeat_Angularjs - Fatal编程技术网

Angularjs ng模型不使用ng repeat

Angularjs ng模型不使用ng repeat,angularjs,Angularjs,我想弄清楚为什么ng模型不能使用ng重复 这是我的代码: $scope.availableCountries = []; APIUtility.getCountries().then(function(data){ $scope.availableCountries = data; $scope.filters.country = "AZ"; }); <select id="eventprice" class="searchpage_select" ng-model="

我想弄清楚为什么ng模型不能使用ng重复

这是我的代码:

$scope.availableCountries = [];
APIUtility.getCountries().then(function(data){
    $scope.availableCountries = data;
    $scope.filters.country = "AZ";
});


<select id="eventprice" class="searchpage_select" ng-model="filters.country">
    <option value="all">show all</option>
    <option ng-repeat="countries in availableCountries" value="{{countries.country_iso}}" ng-class="{'element_selected' : filters.country == countries.country_iso}">{{countries.name}}</option>
</select>
其中:

availableCountries是来自API调用的对象,格式良好,相信我

$scope.filters是一个包含许多筛选器的对象,包括country

问题是,如果我在API调用之前或之后更改ng模型,select语句不会更新,我认为如果我在angular有时间执行ng repeat之前更新范围,ng模型将停止工作,并且不会更新字段

我添加了ng类以证明filters.country具有正确的值。ng class语句在需要时返回true,并将该类添加到正确的位置,因此filters.country包含正确的值

我不知道我是否足够清楚。谢谢大家抽出时间

在选项字段上使用ng选项而不是ng重复

在选项字段上使用ng选项而不是ng重复

问题出在 $scope.filters.country=AZ

试试这个更新的JSFIDLE

http://jsfiddle.net/HB7LU/15021/问题出在 $scope.filters.country=AZ

试试这个更新的JSFIDLE


http://jsfiddle.net/HB7LU/15021/

谢谢,它起作用了,但我需要把country\u iso放在value属性中,现在他添加了一种递增计数器作为value andror,而我需要像androrai这样的东西查看文档,似乎第一个声明应该是value so country.country\u iso as。。。但是没有给我正确的价值。我还尝试了country.country_iso作为country.country_iso for country in Available Countries,以获得country_iso的值和标签,它将iso显示为标签,但此计数器的值仍然为Yes,我应该把country_iso作为值-如果你可以发布一个fiddle或jsbin或其他东西,我可以看到哪里出了问题。比如->即使我的代码有点复杂。正如您所看到的,all选项并不存在。第一个为空,值=?如果我用all预设模型,且值为整数。我还尝试用一个有效的iso预设模型,它可以工作。所以我想我不必关心价值观。。。我认为唯一没有显示其工作状态的all字段,但我需要将country_iso放在value属性中,现在他添加了一种递增计数器作为值Andorra,而我需要一些类似Andorrai的东西查看文档,似乎第一个声明应该是值so country.country_iso as。。。但是没有给我正确的价值。我还尝试了country.country_iso作为country.country_iso for country in Available Countries,以获得country_iso的值和标签,它将iso显示为标签,但此计数器的值仍然为Yes,我应该把country_iso作为值-如果你可以发布一个fiddle或jsbin或其他东西,我可以看到哪里出了问题。比如->即使我的代码有点复杂。正如您所看到的,all选项并不存在。第一个为空,值=?如果我用all预设模型,且值为整数。我还尝试用一个有效的iso预设模型,它可以工作。所以我想我不必关心价值观。。。我认为唯一没有显示的是所有字段
<select id="eventprice" 
        class="searchpage_select" 
        ng-model="filters.country"
        ng-options="country.country_iso as country.name for country in availableCountries">
    <option value="all">show all</option>
</select>