2016-03-30 10 views
0

これは私の角度コードで、changeFilterOption(filter)関数でオブジェクトを受け取る必要があります。このオブジェクトはng-optionでループしています。しかし、それは動作しません;返信undefinesngオプションでng-changeが動作しない

<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 
}; 
+0

は、あなたはそれの構文については、JSのフィドルを作ることができている。これは動作しますが、私は '属性[「+ countInc +」] .name'ための任意のドキュメントを見つけることができません –

答えて

1

をこれはあなたが従う必要がある方法ではありません。このようにしてみてください。

<select ng-change="changeFilterOption(attribute[' + countInc + '].name)" ng-model="attribute[' + countInc + '].name" ng-options="filter.name as filter.uiName for filter in filters"> 
ここ

は、selectの値はchangeFilterOption(filter)filter内のパラメータに渡されるdemo

です。

そして、あなたはchangeFilterOption(filter)filterオブジェクトを渡すために探している場合、あなたは以下のようにselectを変更する必要があり、

<select ng-change="changeFilterOption(attribute[' + countInc + '].name)" ng-model="attribute[' + countInc + '].name" ng-options="filter as filter.uiName for filter in filters"> 

これはselect値としてfilterを選択して、オプションのテキストとしてfilter.uiNameが表示されます。ここ

DEMO

+0

OKのようです。この作品を作るのは何ですか? – Kirk

0

変更のためのあなたができるだけでwatchあなた*.jsファイルでこの

 <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 
      }; 
1

てみてください - あなたはchangeFilterOption関数に選択された値を渡す必要がある場合はその後、

$scope.$watch('your-model-name', function (newValue, oldValue){ 
    //newVal is the changed value 
}); 
関連する問題