-
Notifications
You must be signed in to change notification settings - Fork 3.4k
$mdDialog: bindToController not working? Possibly needs more docs too #1534
Comments
@rschmukler - wonder if a bug was introduced in 0.8-rc1.... |
It seems to work as expected using the latest master from bower-material (0.8.0-rc1-master-f704dda). The issue seems to be that the locals are bound to the controller after its initialization. So, they are not present immediately, but they are there is you wrap the |
@gkalpak Thanks I thought it would be available immediately I think we just need some additions to the docs then. |
Indeed, the variables are not bound to the controller until after its instantiation. I will clarify the docs. |
Would this not make more sense for them to be bound upon instantiation? |
It would. Is it a choice or a limitation? |
From what I can see in the source, it seems to be a limitation of the $controller syntax in angular which means they can't be bound before instantiation... see here... https://github.com/angular/material/blob/master/src/core/services/compiler/compiler.js#L118 |
BTW, it would be possible to have the bindings available upon "instantiation". Angular does this for its directive controllers (with (In an oversimplified version) I think it boils down to the following: // Instead of
var ctrl = $controller(controller, locals); // first instantiating the controller
angular.extend(ctrl, locals); // then binding the values
// Do this:
var instance = Object.create(controller.prototype);
angular.extend(instance, locals);
controller.apply(instance, [/*any DI'ed values*/]); |
@rschmukler - based on @gkalpak feedback, reopening to discuss for 0.10. |
@gkalpak thanks for poking the reinvestigation. Turns out Another case where reading the source can often be the best solution. Thanks! |
Angular is full of "easter-egg-ish", private (aka undocumented) APIs. Thx for fixing this ! |
I was trying to use
$mdDialogs
bindToController
option but it doesn't appear to be working. I checked$scope.myLocal
this.myLocal
and$scope.ctrl.myLocal
but none of them seem to be populated. I also logged the scope it didn't have anything related to my local objects.I checked
$scope.ctrl.myLocal
because I found this test which appears to do that but it didn't work.Also the docs on this are a bit vague they simply say the locals will be copied to the controller. Perhaps a demo using
bindToController
would be helpful.Example trying to use `bindToController
The text was updated successfully, but these errors were encountered: