Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS Drop down values change Dynamically

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.

like image 896
Blu Avatar asked Dec 20 '22 00:12

Blu


1 Answers

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

like image 83
Nitish Kumar Avatar answered Dec 30 '22 18:12

Nitish Kumar