2017-10-18 3 views
0

list1からlist2を更新しようとしていますが、そのためにng-changeを使用しました。選択でng-changeが動作しない

私のアプリは完全に設定されており、htmlページのコントローラは適切に設定されています。

私は私の最初のリスト1からelemtを選択したとき

<label>NameLIst1</label> 
<select ng-model="idLIST1" 
     ng-change="updateList2(idLIST1)" 
     ng-options="elt.id as elt.name for elt in list1"> 

     <option value="">select one</option> 
</select> 

<label>Name LIST 2</label> 
<select ng-model="idLIST2"     
     ng-options="elt.id as id.name for elt in list2"> 

     <option value="">select one</option> 
</select> 


$scope.updateList2 = function(id){ 
alert("id ="+id); 
} 
+0

コンソールにエラーがありますか?アプリはまったく動作しますか? –

+0

作業中の[Plunker](https://plnkr.co)をアップロードしてください... –

+0

'updateList2'関数にパラメータを渡す必要はありません。 '$ scope.updateList2 = function(){alert($ scope.idLIST1)}' – Zooly

答えて

1

をinvocked決してupdateList2方法は、私は以下に書かれたコードを持っていることを唯一のもの、それはPARAMで作業も、正常に動作します。この を試してみてください、 メソッド内でパラメータを渡す必要はありません

<div class="container" ng-controller="TestController"> 
    <label>NameLIst1</label> 
    <select ng-model="idLIST1" 
      ng-change="updateList2(idLIST1)" 
      ng-options="elt.id as elt.name for elt in list1"> 

     <option value="">select one</option> 
    </select> 

    <label>Name LIST 2</label> 
    <select ng-model="idLIST2" 
      ng-options="elt.id as id.name for elt in list2"> 

     <option value="">select one</option> 
    </select> 
</div> 

var app = angular.module("test", ["ngRoute"]) 
     .controller("TestController", ['$scope', function ($scope) { 
      $scope.list1 = [ 
       { id: 1, name: 'data1' }, 
       { id: 2, name: 'data2' }, 
       { id: 3, name: 'data3' }, 
       { id: 4, name: 'data4' }, 
      ]; 
      $scope.updateList2 = function (id) { 
       alert("id =" + id); 
      } 
     } 
     ]); 
関連する問題