AngularJS下拉值动态更改

时间:2013-09-21 12:26:30

标签: angularjs angularjs-controller

我使用AngularJS创建了两个下拉列表,并通过控制器在其中附加了数据。我希望在第一次下拉时发生更改时更改第二个下拉值。

我创建example,但是当我更改第一个下拉列表的值时;第二个下拉值不会改变。

1 个答案:

答案 0 :(得分:11)

更新了HTML:

<div ng-controller="exerciseTypeCtrl">

<ul data-role="listview" data-inset="true" >
<li>
    <select id="exerciseSuperCategory" data-role="listview" ng-options="catagory as catagory.text for catagory in catagories.cast " ng-model="itemsuper" ng-change="changeData()">
    </select>
</li>
</ul>       
<ul data-role="listview" data-inset="true">
<li>
    <select data-role="listview" ng-options="type as type.text for type in types.cast " ng-model="item1" ng-change="update()">

    </select>
</li>
</ul>

更新了控制器:

myApp.controller('exerciseTypeCtrl',function($scope,indoors,outdoors,setNulls, catagories){

$scope.catagories = catagories;
$scope.types = setNulls;
$scope.changeData = function() {
    //console.log($scope.itemsuper);

    if($scope.itemsuper.text == "Indoor") {
        $scope.types = indoors;
    } else if($scope.itemsuper.text == "Outdoor") {
        $scope.types = outdoors;
    } else {
        $scope.types = setNulls;
    }
 }
});

Updated Example