likeastore / ngDialog

Modals and popups provider for Angular.js applications
http://likeastore.github.io/ngDialog
3.14k stars 692 forks source link

$onInit isn't executed #550

Open thany opened 7 years ago

thany commented 7 years ago

What version of ng-dialog are you using? 1.1.0

What version of AngularJS are you using? 1.6.4

Please describe the issue I've made a dialog with its own controller, with controllerAs and bindToController:

ngDialog.open({
  name: "foo",
  trapFocus: false,
  template: "/path/to/template/foo.html",
  controller: "FooController",
  controllerAs: "vm",
  bindToController: true,
  resolve: {
    bar() { return 42; }
  }
});

In the controller:

module.controller("FooController", ["bar", function(bar) {
  this.$onInit = function() {
    this.bar = bar;
    console.log(this);
  };
  console.log(this);
}]);

What did you expect to happen? $onInit should be executed - I should see two console logs.

What actually happened? $onInit is not executed - I see only the second console log.

thany commented 7 years ago

Here we have the ugliest workaround to get $onInit to execute anyway:

.controller("FooController", ["bar", function(bar) {
  this.$onInit = function() {
    this.$onInit.executed = true;
    // ...
  };

  // ...

  !this.$onInit.executed && this.$onInit();
}]);
thany commented 7 years ago

Might be a nice option if this were fixed, wouldn't it? :)

mathiasmoeller commented 6 years ago

Any news if this will be fixed anytime soon?