Angular Model Value Usage
by vinodlouis
HTML
<div ng-controller="parentCtrl" ng-app="myApp">
<select ng-change="changesecond()"
ng-model="myOptionSub"
ng-options="subjectobj.code as subjectobj.name for subjectobj in subject.subarray">
</select>
<div>subject model: {{myOptionSub}}</div>
<div>subject model: {{exam.myOptionSub}}</div>
<select
ng-model="myOptionExam"
ng-options="examobj.examcode as examobj.name for examobj in exam.myOptionSub">
</select>
<div>exam model: {{myOptionExam}}</div>
</div>
JavaScript
var myApp = angular.module('myApp', []);
myApp.controller('parentCtrl',['$scope','$window','$location',function ($scope,$window,$location) {
$scope.subject={"subarray":[
{'name':'science','code':'sci'},
{'name':'maths','code':'mat'}
]};
$scope.exam={"sci":[{'name':'science 1','examcode':'s1'},
{'name':'science 2','examcode':'s2'}
],
"mat":[
{'name':'maths 1','examcode':'m1'},
{'name':'maths 2','examcode':'m2'}
]
};
$scope.changesecond = function(){
$scope.exam.myOptionSub = $scope.exam[$scope.myOptionSub];
$scope.myOptionExam = $scope.exam.myOptionSub[0].examcode;
}
$scope.myOptionSub = "sci"
$scope.exam.myOptionSub = $scope.exam["sci"];
$scope.myOptionExam = $scope.exam["sci"][0].examcode;
}]);