簡體   English   中英

ng-change不適用於ng選項

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM