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

回答

0

所以我解決了這個問題,特別是爲這個mdDialog創建了嵌套控制器,所以它不能調用除了我的新控制器中的東西外的其他東西。作爲關於嵌套控制器的參考,我使用了https://docs.angularjs.org/guide/controller