我正在尝试使用模式来允许用户编辑以前保存的选项。我遇到的问题是模态中的更改会立即保存,而不是仅在用户单击保存后才能保存。因此,如果用户在模态中进行更改,然后取消,则仍会保存更改。
有关如何在用户点击保存之前阻止更改的任何建议?
.controller('EditProjectCtrl',
function ($location, $stateParams, Projects, $modalInstance) {
var editProject = this;
var projectId = $stateParams.projectId,
projectIndex;
editProject.projects = Projects;
projectIndex = editProject.projects.$indexFor(projectId);
editProject.project = editProject.projects[projectIndex];
editProject.options = [
{'type': 'Small', 'cost': 10},
{'type': 'Medium', 'cost': 10},
{'type': 'Large', 'cost': 10}
];
editProject.cancel = function () {
$modalInstance.dismiss('cancel');
};
editProject.destroy = function () {
$modalInstance.close(editProject.selected);
editProject.projects.$remove(editProject.project).then(function (data) {
$location.path('/selection');
});
};
$modalInstance.result.then(function(selectedItem) {
editProject.selected = selectedItem;
},
editProject.save = function () {
$modalInstance.close(editProject.selected);
editProject.projects.$save(editProject.project).then(function (data) {
$location.path('/selection');
});
})
})