Angularjs $mdDialog在调用时向api发送附加请求
我使用mdDialog在web应用程序中创建新对象。每当我调用mdDialog时,它总是调用我在angular controller中拥有的所有方法。我怎样才能预防它 下面是一个带有mdDialog函数的角度控制器的简短示例Angularjs $mdDialog在调用时向api发送附加请求,angularjs,angularjs-scope,mddialog,Angularjs,Angularjs Scope,Mddialog,我使用mdDialog在web应用程序中创建新对象。每当我调用mdDialog时,它总是调用我在angular controller中拥有的所有方法。我怎样才能预防它 下面是一个带有mdDialog函数的角度控制器的简短示例 //whenever i click on button which invokes showCreateTask function //these 3 methods get invoked also and send request to my api
//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
导致了我的问题,但我不知道如何解决它。如果我从函数中删除控制器,则不会有任何效果。所以我通过创建嵌套控制器解决了这个问题,特别是为这个mdDialog创建嵌套控制器,这样它就不能调用除新控制器中的内容之外的任何其他内容。作为我使用的嵌套控制器的参考