0
我使用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
引起我的問題,但我不知道如何解決它。如果我從功能中刪除控制器,什麼都不會起作用。