2017-09-20 2 views
0

のモデルコントローラで親コントローラのアレイオブジェクトを変更:ではないことが、私は次のことを行っているangularjs 1

var appController = function ($scope,$uibModal) { 
$scope.list = [ 
{ 
    "parentId": 0, 
    "id": 1, 
    "title": "node1", 
    "description": "test", 
    "canhaveItems": true, 
    "canhaveSubNode": true, 
    "items": [{ "id": "item1", "title": "item1" }], 
    "nodes": [ ] 
}; 


$scope.newTopNode = function() { 
    var modalInstance = $uibModal.open({ 
     templateUrl: '../modal.html', 
     controller: function ($scope) { 
      $scope.handler = 'pop'; 
      $scope.buttonText = "Add Group"; 
      $scope.body = 'Add New Top Group'; 
      $scope.save = function() { 
       var subNode = { 
        "parentId": 0, 
        "id": 100, 
        "title": $scope.txtGroup, 
        "description": $scope.txtDescription, 
        "canhaveItems": $scope.chbItems, 
        "canhaveSubNode": $scope.chbSubGroup, 
        "items": [], 
        "nodes": [] 
       }; 
     // here I need to update the parent List 
     //I tried like this 
     // $scope.list.push(subNode); // but parent list is not updating 
       modalInstance.close(); 
      }; 
      $scope.cancel = function() { 
       modalInstance.dismiss('cancel'); 
      }; 
     } 
    }); 
}; 
} 

Iは 解決を使用してのような別のものを試してみました:関数(){サブノードを返す;} 範囲:$ scope スコープ:this.parent ただし、モデルコントローラ内の親配列オブジェクトを更新する際の助けが必要です。おかげさまで

答えて

0

私はトップコントローラ

var parent = $scope; 

で変数を作成し、この

parent.list.push(subNode); 

おかげのようなモデルのコントローラにリストオブジェクトにアクセスしました。

関連する問題