2016-07-22 7 views
2

ここでトリガ私のコントローラである:最初に、一度だけNG-の変化は、一度だけ

<tr> 
                  <td> 
                   <label for="sel1">Product Type</label> 
                   <select class="form-control" id="sel1" ng-model=productTypes ng-change="getProductVersions()"> 
                   <option ng-repeat="type in ctrl.productTypes" value="" > 
                    {{type.name}} 
                   </option>                
                   </select> 
                  </td> 
                 </tr> 

                 <tr> 
                  <td> 
                   <label for="sel1">Product Version</label> 
                   <select class="form-control" id="ver" ng-model="productVersions" > 
                   <option ng-repeat="version in ctrl.productVersions" value="" > 
                    {{version.productVersion}} 
                   </option>                
                   </select> 
                  </td> 
                 </tr> 

NG-変更がトリガされます。

 App.controller('LicenseController', ['$scope', 'licenseService', function($scope, licenseService) { 
     var self = this; 

     $scope.productTypes = {name:'', productID:''}; 
     self.productTypes = {name:'', productID:''}; 
     $scope.selectedProduct = {name:'', productID:''}; 
     $scope.productVersions = {productVersion:'', versionID:''}; 
     self.productVersions = {productVersion:'', versionID:''}; 

     $scope.fetchProductType = function(){ 
      licenseService.fetchProductType() 
       .then(
          function(d) { 
           self.productTypes = d; 
           $scope.productTypes = d; 
           console.log($scope.productTypes[1].name); 
           console.log($scope.productTypes[1].productID); 
          }, 
          function(errResponse){ 
           console.error('Error while fetching Currencies'); 
          } 
        ); 
     }; 

     $scope.fetchProductType(); 

     $scope.getProductVersions = function(){ 

      console.log($scope.selectedProduct.productID); 
      licenseService.getProductVersions($scope.selectedProduct.productID) 
        .then( 
          function(d) { 
           $scope.productVersions = d; 
           self.productVersions = d; 
           console.log($scope.productVersions[1].productVersion); 
           console.log($scope.productVersions[1].versionID); 
         }, 
          function(errResponse){ 
           console.error('Error while creating User.'); 
          } 
      ); 
     }; 

    }]); 

とHTML製品タイプの変更。また、選択した製品タイプを変更したい場合もあります。誰かが私がこれをやる方法を手伝ってもらえますか

答えて

2

同様の問題が発生しました。私がそれを修正する方法は、オプションを調べる代わりにng-optionsディレクティブを使用していました。ここで

は角の1.xのドキュメントの例です:

<select ng-model="myColor" ng-options="color.name group by color.shade for color in colors"> 

https://docs.angularjs.org/api/ng/directive/ngOptions