-
Notifications
You must be signed in to change notification settings - Fork 3.4k
bindToController and $onInit #9259
Comments
Also #8153 accounts for that issue. |
@devversion - related to Component API support. |
@devversion - status update on this ? |
@devversion Hi. Has this been implemented in any version on NPM? We're using ES6 and can't get anything to pass into the $mdToast instance. |
@mcblum We internally had a lot of discussion about this change in Angular, and we are planning to make our
In meanwhile if you can explain what specific issue you have? I might be able to help you with that. |
@devversion Thank you! Basically I'm using ES6 / Webpack for the very first time and we want to do a $mdToast.show(). What we're finding is that the templateUrl doesn't work because everything is moved around once it's served and the locals : {
"message" : "Test message"
} and then in the controller |
@mcblum No problem. I think there is a bit confusion about the
|
Thank you @devversion! Does it change anything that I'm using ES6 syntax? I tried to copy your example and ended up with the error: show(params) {
let options = {
template: `<md-toast>
<div class="md-toast-content" ng-class="$ctrl.type">
{{$ctrl.message}}
<md-button ng-click="hide()">Dismiss</md-button>
</div>
</md-toast>`,
controller: toastController(),
locals: {
message: "test",
title: params.title,
classes: params.classes
},
controllerAs: '$ctrl',
hideDelay: 50000,
bindToController: true
};
this.$mdToast.show(options);
function toastController() {
}
} |
I should mention I also tried making toastController an ES6 class and importing it and such and then I got |
I just encountered this issue too. We're using Typescript with target I made a pen to show it off clearly: http://codepen.io/anon/pen/LxxGZr A workaround for now is to use DI with |
So where do we stand with this? My issues is that $onInit hook is not called when the controllers is used for mdDialog. |
@csvn Thanks so much for the pen! This is such a better way to use dialogs. Sadly you are right, this still does not work with your pen. But I happen to be using Typescript with |
I encountered a similar issue... I am not sure what the order of the digest cycle and initialization code is. I can tell To get it to work I had to introduced a hack to delay initialization code (of computed variables) using this.$timeout( () => {
....
}, 100); |
This should be fixed by fa997b9, it just needs a release. |
Actually, it has already been released in |
Actual Behavior:
What is the issue? *
I am using $mdDialog bindToController option with TypeScript classes transcompiled to es6. My locals are not getting bound to the controller. With es5 option, the locals are getting bound to the controller.
Looking at the AngularJS documentation, they are depreciating binding to the controller before a constructor is being called (even for es5). As per the attached AngularJS discussion, this will be depreciated by AngularJS 1.6 (not a default option). So this will soon become a bug.
Properties set before constructor is called when using bindToController angular.js#14206
I am using $onInit function to initialize the controller bound values. This $onInit function is not getting called.
What is the expected behavior?
$onInit function should be called when bindToController is set to true
CodePen (or steps to reproduce the issue): *
CodePen Demo which shows your issue:
Details:
Angular Versions: *
Angular Version:
1.5.8Angular Material Version:
v1.1.0-rc.5Additional Information:
Browser Type: *
ChromeBrowser Version: *
51.0.2704.103 mOS: *
Windows 10Stack Traces:
Shortcut to create a new CodePen Demo.
Note:
*
indicates required information. Without this information, your issue may be auto-closed.The text was updated successfully, but these errors were encountered: