AngularJS Drop down values change Dynamically

北城以北 提交于 2019-12-22 09:10:56

问题


I have created two drop downs using AngularJS and appended data in them through the controllers. I want to change the second drop down values when a change occurs in first drop down.

I create the example, but when I change value of the first drop down; the second drop down values do not change.


回答1:


Updated 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>

Updated Controller:

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



来源:https://stackoverflow.com/questions/18932585/angularjs-drop-down-values-change-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!