[英]ng-change not working with ng option
這是我的角度代碼,我需要通過changeFilterOption(filter)
函數接收對象,此對象在ng-option中循環。 但這是行不通的;返回undefines
。
<select ng-change="changeFilterOption(filter)" class="js-example-basic-single form-control" ng-model="attribute[' + countInc + '].name" ng-options="filter.name as filter.uiName for filter in filters"></select>
$scope.changeFilterOption=function(filter){
console.log(filter);//undefined
};
如果您需要將選定的值傳遞給changeFilterOption
函數,則這不是您需要遵循的方法,請嘗試這樣,
<select ng-change="changeFilterOption(attribute[' + countInc + '].name)" ng-model="attribute[' + countInc + '].name" ng-options="filter.name as filter.uiName for filter in filters">
這是演示
然后將select
值傳遞給filter
參數中的changeFilterOption(filter)
。
而且,如果您希望將filter
對象傳遞給changeFilterOption(filter)
則需要如下修改select
,
<select ng-change="changeFilterOption(attribute[' + countInc + '].name)" ng-model="attribute[' + countInc + '].name" ng-options="filter as filter.uiName for filter in filters">
這將選擇filter
作為select
值,並顯示filter.uiName
作為選項文本。
這是演示
在您的*.js
文件中,您只需watch
更改即可:-
$scope.$watch('your-model-name', function (newValue, oldValue){
//newVal is the changed value
});
嘗試這個
<select ng-change="changeFilterOption(filter)" class="js-example-basic-single form-control" ng-model="attribute[' + countInc + '].name" ng-options="filter as filter.uiName for filter in filters"></select>
$scope.changeFilterOption=function(filter){
console.log(filter);//undefined
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.