我做了以下事情:
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');
};
}
});
};
}
我尝试过不同的东西,比如使用 resolve:function(){return subNode;} 范围:$ scope 范围:this.parent 但没有用,在这里寻找一些帮助更新模型控制器内的父数组对象。 感谢。
答案 0 :(得分:0)
我在顶级控制器中创建了一个变量
var parent = $scope;
并像这样访问模型控制器中的列表对象
parent.list.push(subNode);
感谢。