mdDialog: controller functions not being called in 1.1.1
Actual Behavior:
What is the issue? *Since updating to 1.1.1 it seems that calling a function inside a dialog controller no longer works. In version 1.1.0-rc5, this was not an issue. Using Batarang in my application, it says that the functions defined inside the dialog controller are undefined.What is the expected behavior?Calling a function that is defined in a dialog controller should work.
CodePen (or steps to reproduce the issue): *
CodePen Demo which shows your issue:http://codepen.io/Bash4195/pen/VKvAzb?editors=1010Details:The code pen demonstrates the first button opening a dialog which has 3 buttons at the bottom. One is supposed to close the dialog, one is supposed to hide it and the last simply logs "Hello world!" to the console. These link to functions defined in the dialog's controller which do not run. The second button does the same thing except the dialog button functions are defined in the root of the controller like regular Angular variables and so they run fine.
Angular Versions: *
Angular Version:1.5.5 & 1.5.7 testedAngular Material Version:1.1.1
Work Around: Define functions that need to be run by a dialog inside the root of the controller.
This is not a bug, because the controller you created will be never instantiated.
The purpose of a contentElement is to not compile and link it to any scope (this also includes controller instantiation)
There two options to fix this
- Use a normal template instead
- Manually link the controller once (as pre-rendered)
<md-dialog ng-controller="MyController"></md-dialog>
Anyways I think we need to document this specific situation better.
This is how I always used them in the previous version. But I guess I was wrong to do so. Thanks for the reply, just trying to help out!
@Bash4195 Thanks it's much appreciated! Makes this functionality more clear and better :)
Let's keep this issue open, so I can keep track of the lack of documentation :)
Ohh sorry, no problem! :)
I'm not using contentTemplate but template with require but I still do not understand why the controller is never insantiated :(
this.$mdDialog.show({
template: require("./test-view-save.template.html"),
clickOutsideToClose: true,
escapeToClose: true,
controller: TestViewSaveController,
}).then(
(r) => { console.log("resolve?") },
() => { console.log("canceled") }
)
I'm lost here...
@ssamayoa please take a look at the $mdDialog docs and direct any further questions to Stack Overflow, Gitter, or the AngularJS Material forums.