我使用 mdDialog 在我的 Web 应用程序中创建新对象。每当我调用 mdDialog 时,它总是调用我在我的角度控制器中拥有的所有方法。我该如何预防?
这是我的带有 mdDialog 功能的角度控制器的简短示例
//whenever i click on button which invokes showCreateTask function
//these 3 methods get invoked also and send request to my api
$scope.timeline = new TimelineService();
$scope.users = UserService.getChatUsers();
$scope.projects = ProjectService.query();
/*********DIALOGS************/
$scope.hide = function () {
$mdDialog.hide();
};
$scope.cancel = function () {
$mdDialog.cancel();
};
$scope.answer = function (answer) {
$mdDialog.hide(answer);
};
$scope.createTask = function () {
TaskService.save($scope.task, function () {
});
}
$scope.showCreateTask = function (ev) {
$mdDialog.show({
controller: TaskController,
templateUrl: 'app/components/templates/CreateTaskDialog.html',
parent: angular.element(document.body),
targetEvent: ev,
clickOutsideToClose: true,
fullscreen: false,
scope: $scope,
preserveScope: true,
onComplete: function () {
//Timepicker
angular.element(".timepicker").timepicker({
showMeridian: false,
showInputs: false,
minuteStep: 5,
defaultTime: '00:00'
});
}
})
.then(function () {
}, function () {
//fail
});
};
我发现这controller: TaskController
导致了我的问题,但我不知道如何解决它。如果我从功能中删除控制器,什么都不会起作用。