我正在尝试使用模态窗口(请参阅http://angular-ui.github.io/bootstrap/)。模态窗口中的范围(AngularJS指令)
在父控制器I具有以下功能:
$scope.open = function() {
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: ModalInstanceCtrl,
resolve: {
year: function() {
return $scope.year.value;
},
month: function() {
return $scope.month;
},
day: function() {
return $scope.day.name;
},
todos: function() {
return $scope.day.toDoItems;
}
},
backdrop: 'static'
});
modalInstance.result.then(function (todos) {
angular.forEach(todos, function (todo) {
if (todo.New)
$scope.day.toDoItems.push(todo);
});
}, function() {
$log.info('Modal dismissed at: ' + new Date());
});
};
而在模态控制器有一个addTodo功能:
var ModalInstanceCtrl = function ($scope, $modalInstance, year, month, day, todos) {
...
$scope.todos = todos;
$scope.addTodo = function() {
$scope.todos.push({ TodoText: $scope.todoText.value, Done: false, Del: false, Date: new Date(year, month, day), Priority: 1, New: true});
$scope.todoText.value = "";
};
...
$scope.ok = function() {
$modalInstance.close($scope.todos);
};
};
在父视图,示出与todos
日历每天。当点击一天的标题时,模式窗口打开,您可以添加待办事项。我的问题是,在模态窗口中添加待办事项时,todos
也会同时添加到父视图中。 现在todos
在父视图中添加了两次:一次在模态视图中添加它们,一次在模态视图上单击确定。 但我希望todos
项目仅在单击模式视图上的确定时才会添加到父视图。
有没有人为此提供解决方案?提前致谢!
您可以在Plunker看看它是如何工作的:http://plnkr.co/edit/Nr1h7K3WZyWlRlrwzhM3?p=info
你可以说明,在小提琴? –
我已经添加了一个来自Plunker的链接,我无法编辑小提琴的html标签(我必须指定ng-app)。 – Tenzi