ng-repeat不适用于选项标签

时间:2017-05-26 12:10:17

标签: javascript angularjs

我有第一个选择更改的城市数组,我想在第二个选项列表中显示; 但它并没有显示出来。

在角度控制器中

<select ng-change="getCities()" ng-model="state" required>
  <option value="Bihar">Bihar</option>
  <option value="Chhattisgarh">Chhattisgarh</option>
  <option value="Delhi">Delhi</option>
</select>

<select name="city" required>
  <option ng-repeat="city in citieslist">{{ city }}</option>
</select>

在HTML中选择

@Component
public class MyListener 
        implements ApplicationListener<ContextRefreshedEvent> {

    public void onApplicationEvent(ContextRefreshedEvent event) {
        //Here call your method of cache
        // Your methode will be called after the application context has fully started
    }
}

感谢。

3 个答案:

答案 0 :(得分:0)

将其更改为

<select ng-repeat="city in citieslist" name="cityList" required>
<option >{{ city }}</option>
  </select>

答案 1 :(得分:0)

.controller('addUserCtrl', function($scope,$http) {
    $scope.citieslist = ["Nagpur", "Pune", "Latur", "Aurangabad"];
     $scope.getCities = function() {
       $scope.citieslist = $scope.citieslist;
     };
  });

尝试使用此代码,您已在getCities()内分配了一个列表,它将在ng-change="getCities()"处理,但无法在ng-repeat分配值。所以你需要将它分配出方法然后你可以在方法内再次分配它,然后它将工作。检查plunker

中的代码

答案 2 :(得分:-2)

更改下拉列表html代码,如下所示

<select name="citys" ng-repeat="city in citieslist" required>
  <option>{{ city }}</option>
</select>