嗨,我正在開發Angularjs應用程序。我有兩個下拉列表框。每當我在第一個下拉列表中選擇一些東西,然後根據firstdropdown的值,第二個firstdropdown將加載(Cascading dropdownlistbox)。我正在使用Ajax調用將數據綁定到dropdownlist。 以下是我的index.html,其中有兩個dropdownlistboxe。Angularjs ng-change沒有觸發
<select ng-model="selectedMake" ng-options="b for b in list" id="brand" ng-change="getModel(selectedMake)">
<option value="">-- Select a Make --</option>
</select>
<select ng-model="selectedModel" ng-options="b for b in Modellist" id="brand">
<option value="">-- Select a Model --</option>
</select>
這是我的控制器代碼。 var arrMakes = new Array();
$http.get("http://localhost:4739/api/AutoLease/GetVehicleMake").success(function (data) {
$.map(data, function (item) {
arrMakes.push(item.MakeName);
});
$rootScope.list = arrMakes;
}).error(function (status) {
});
$rootScope.getModel = function (selectedMake) {
debugger;
var arrModel = new Array();
$http.get(url + 'api' + '/AutoLease/' + selectedMake + '/GetVehicleModel').then(function (response) {
$.map(data, function (item) {
arrModel.push(item.ModelName);
});
$rootScope.Modellist = arrModel;
});
}
我可以加載第一個下拉菜單。在第一個下拉列表中,我有getModel函數在ng-change事件中。此事件並未解僱。我也沒有收到任何錯誤消息。我可以知道我在這裏失蹤的事嗎?提前致謝。
創建Plunker請登錄 –
我想你不需要在getModel函數中傳遞selectedMake。只需在函數中訪問$ scope.selectedMake就可以獲得選定的值,並且請提供任何jsfiddle或plunker,以便您快速得到答案,其他人可以輕鬆理解。嘗試設置$ scope而不是$ rootScope。 –
謝謝。請在這裏找到。 https://plnkr.co/edit/Wx0z64cLkRm129KTrj9T?p=preview –