は、以下のこのコードを試してみてください。
index.htmlを
<div data-ng-app="myApp" data-ng-controller="StateController as stateCtrl">
States :
<select id="source" name="source" data-ng-model="dataState" data-ng-options="state.id as state.name for state in states" data-ng-change="stateCtrl.changeState(dataState)">
<option value="">Select State</option>>
</select>
Districts:
<select id="status" name="status" data-ng-options="district.id as district.name for district in districts">
<option>{{district.name}}</option>
</select>
</div>
app.js
var state = angular.module("myApp", []);
state.controller('StateController', ['$window', '$scope', function($window, $scope) {
$scope.states = [{id: 1, name: 's1'}, {id: 1, name: 's2'}, {id: 1, name: 's3'}]; $scope.districts = {};
this.changeState = function(id) {
//Add whatever condition u need. Below code is a hard coded way. I recommend using ajax request to fetch district results based on states
if (id === 1) {
$scope.districts = [{id: 1, name: 'd1'}, {id: 1, name: 'd2'}, {id: 1, name: 'd3'}];
} else if (id === 2) {
$scope.districts = [{id: 1, name: 'd4'}, {id: 1, name: 'd5'}, {id: 1, name: 'd6'}];
}
}
}]);
を説明するように、あなたが最初の行にタイプミスをした重複が削除され、別の配列に保つ、あるいは独自のフィルターを使用することができます。これは 'ng-controller 'でなければなりません。 – Nisarg
あなたは、地区で何らかのフィルタリングをしたいと思うようです。詳細はこちらをご覧ください:https://docs.angularjs.org/api/ng/filter/filter –