How does $mdDialog work with promise and $scope?

vincentf

I'm new to angular, trying to use angular material to create a popup dialog. I'm confused with the promise and $scope here. If I click the dialog button, console will show 'created' and then no window will popup. But if I change it to .then(createFolder, ..), function createFolder(){...}, everything is ok.

$scope.createFolder = function(ev) {
  $mdDialog.show({
    controller: dialogController,
    templateUrl: 'dialog_new_folder.html',
    parent: angular.element(document.body),
    targetEvent: ev,
    clickOutsideToClose:true,
  })
  .then($scope.createFolder, $scope.cancelDialog);
};

$scope.createFolder = function() {
  console.log('created')
}
$scope.cancelDialog = function() {
  console.log('cancelled')
}


function dialogController($scope, $mdDialog) {
          $scope.folderName = '';
          $scope.hide = function() {
            $mdDialog.hide();
          }
          $scope.cancel = function() {
            $mdDialog.cancel();
          }
        }
Jonathan Rupp

You're using $scope.createFolder for both the function to call when the dialog is closed successfully, and for the function to show the dialog. Your second declaration is overwriting your first. Rename one of them.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How does scope work in Io?

From Dev

How does scope work in Ruby?

From Dev

How to share scope between controller and $mdDialog?

From Dev

What is the skimlinks scope and how does it work

From Java

How does the scope of variables in julia modules work?

From Dev

How does this hoisting work with block scope?

From Dev

How does this hoisting work with block scope?

From Dev

How Does Spring Batch Step Scope Work

From Dev

What is the skimlinks scope and how does it work

From Dev

How does $.ajax success scope work?

From Dev

how does jsp:useBean scope attribute work?

From Dev

How does promise.all work?

From Dev

How does the 'catch' work in a native Promise chain?

From Dev

How to assign scope in a promise?

From Dev

Angular $scope does not work

From Dev

Angular $scope does not work

From Dev

Why does it work with $scope but not with `this`?

From Dev

$scope.formName.$setPristine() does not work ; How to reset form in angular?

From Dev

How does $scope.apply() work exactly in AngularJS?

From Dev

how does $scope in controllers work and different ways of declaring controllers?

From Dev

What is the scope of the Single Responsibility Principle and how does it work with DRY?

From Dev

How does the session scope of a bean work in a Spring MVC application?

From Dev

How does variable scope work within the Mocha test framework?

From Dev

Prolog: how does variable instantiating work, what is the scope of local variables

From Dev

Prolog: how does variable instantiating work, what is the scope of local variables

From Dev

Function declared outside class scope but not friend. How does this work?

From Dev

how does scope work when using property in Python 3?

From Dev

Why does the scope work like this?

From Java

How does Promise chain work when one callback doesn't return any promise?

Related Related

  1. 1

    How does scope work in Io?

  2. 2

    How does scope work in Ruby?

  3. 3

    How to share scope between controller and $mdDialog?

  4. 4

    What is the skimlinks scope and how does it work

  5. 5

    How does the scope of variables in julia modules work?

  6. 6

    How does this hoisting work with block scope?

  7. 7

    How does this hoisting work with block scope?

  8. 8

    How Does Spring Batch Step Scope Work

  9. 9

    What is the skimlinks scope and how does it work

  10. 10

    How does $.ajax success scope work?

  11. 11

    how does jsp:useBean scope attribute work?

  12. 12

    How does promise.all work?

  13. 13

    How does the 'catch' work in a native Promise chain?

  14. 14

    How to assign scope in a promise?

  15. 15

    Angular $scope does not work

  16. 16

    Angular $scope does not work

  17. 17

    Why does it work with $scope but not with `this`?

  18. 18

    $scope.formName.$setPristine() does not work ; How to reset form in angular?

  19. 19

    How does $scope.apply() work exactly in AngularJS?

  20. 20

    how does $scope in controllers work and different ways of declaring controllers?

  21. 21

    What is the scope of the Single Responsibility Principle and how does it work with DRY?

  22. 22

    How does the session scope of a bean work in a Spring MVC application?

  23. 23

    How does variable scope work within the Mocha test framework?

  24. 24

    Prolog: how does variable instantiating work, what is the scope of local variables

  25. 25

    Prolog: how does variable instantiating work, what is the scope of local variables

  26. 26

    Function declared outside class scope but not friend. How does this work?

  27. 27

    how does scope work when using property in Python 3?

  28. 28

    Why does the scope work like this?

  29. 29

    How does Promise chain work when one callback doesn't return any promise?

HotTag

Archive