2015-11-15 57 views
0

Angularjs代碼。爲角度和地圖綁定中的現有地圖帶來新的價值

$scope.model; 

我定義我的新對象中的角像以下

$scope.newRelation = { 
    relationType : null, 
    relatedModel : null 
}; 

HTML

  <div class="table-responsive"> 
       <table class="table"> 
        <tr> 
         <td><select class="form-control" 
          ng-model="newRelation.relationType" required 
          ng-options="modeltype as modeltype for modeltype in modeltypes"></select> 
         </td> 
         <td><select class="form-control" 
          ng-model="newRelation.relatedModel" required 
          ng-options="model.name as model.name for model in models"></select> 
         </td> 
         <td> 
          <button type="button" class="btn btn-default" 
           ng-click="addRelation()">Add Relation</button> 
         </td> 
        </tr> 
       </table> 
      </div> 

角代碼

$scope.addRelation = function() 
{ 
    $scope.model.relations.push($scope.newRelation); 
}; 

當我點擊形式保存model.relations值在廣管局中是空的ck結束。任何線索?請讓我知道是否需要提供更多信息

回答

0

您直接將對象分配給列表。

它會繼續引用。

進行復印

var obj=angular.copy($scope.newRelation); 

然後將其推

$scope.model.relations.push(obj);