ng-repeat中的ng-model不起作用,我无法更新ng-repeat的所有值

时间:2017-04-20 08:50:05

标签: php angularjs ionic-framework

在代码中,有ng-repeat,我必须更新frais显示的所有值的ng-repeat。我无法更新frais,因为它位于ng-repeat内部,当我将其放在外面时它可以正常工作,但我必须将其放入更新ng-repeat的每个值。

file.html

<ion-content class="padding" ng-controller="FactureAdminCtrl">

<ion-list ng-repeat = "selectedName in selected">
      <div class="item item-divider center-text" 
           name="codeE" ng-model="selectedName.CodeEnvoiColis"> 
        {{selectedName.CodeEnvoiColis}}
      </div>  

      <label class="item item-input">
      <input width="20%" type="text" 
          placeholder="Frais" ng-model="selectedName.FraisFact" 
          style="color:#BA1B1B;">
      </div> 
      </label>

</ion-list>  

    <a class="button button-info" href="#/factureAdmin" `
          ng-click=updateFact(selectedName)> Submit </a>

app.js

$scope.updateFact = function(selectedName){ 

   $http.post(  
        "http://localhost/deb/updatFact.php",  
        { 

        'FraisFact':$scope.selectedName.FraisFact,
        'CodeEnvoiColis':$scope.selectedName.CodeEnvoiColis,
      }
   ).success(function(data){  
        alert(data);                                
   });  

} 

我该怎么办!

1 个答案:

答案 0 :(得分:0)

为ng-repeat内的ng-model提供索引     

<ion-list ng-repeat = "(key,value) in selected" {{selectedName[key]=value;""}}>
          <div class="item item-divider center-text" name="codeE" ng-model="selectedName[key].CodeEnvoiColis"> {{selectedName[key].CodeEnvoiColis}} </div>  

          <label class="item item-input">
          <input width="20%" type="text" placeholder="Frais" ng-model="selectedName[key].FraisFact" style="color:#BA1B1B;"></div> 
          </label>
</ion-list>  

    <a class="button button-info" href="#/factureAdmin" ng-click=updateFact(selectedName[key])> Submit </a>

app.js

$scope.selectedName = []; //defined empty

$scope.updateFact = function(selectedName){ 

           $http.post(  
                "http://localhost/deb/updatFact.php",  
                { 

                'FraisFact':selectedName.FraisFact,
                'CodeEnvoiColis':selectedName.CodeEnvoiColis,
              }
           ).success(function(data){  
                alert(data);                                
           });  
    } 

app.js第二版:更新所有值

<a class="button button-info" href="#/factureAdmin" ng-click=updateFact()> Submit </a>

app.js

$scope.selectedName = []; //defined empty

$scope.updateFact = function(){ 

            console.log("check if values updating ", $scope.selectedName)

           $http.post(  
                "http://localhost/deb/updatFact.php",  
                { 

                data: $scope.selectedName   //put logic on backend to update all data
              }
           ).success(function(data){  
                alert(data);                                
           });  
    }