Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Bug: bindToController and locals with es6 classes not working #11061

Closed
mribichich opened this issue Jan 11, 2018 · 1 comment
Closed

Bug: bindToController and locals with es6 classes not working #11061

mribichich opened this issue Jan 11, 2018 · 1 comment

Comments

@mribichich
Copy link

Bug:

After changing typescript target to es6, locals bindings with bindToController = true stopped working, for example with $mdDialog.show(...)

I updated to latest v1.1.5, and the problem remains.

What is the expected behavior?

It should bind the locals to the controller directly without passing them to the constructor

this.$mdDialog
      .show({
        controller: SomeController,
        bindToController: true,
        locals: {
          data: someData
        },
        ...
      });

class SomeController {
}

After initialization $ctrl.data should be there

What is the current behavior?

It doesn't bind the locals to the controller when using classes, so $ctrl.data is undefined

CodePen and steps to reproduce the issue:

CodePen Demo which shows your issue:

https://codepen.io/mribichich/pen/OzZRYo

Detailed Reproduction Steps:

Using with function works, using it with classes it doesnt

Which versions of AngularJS, Material, OS, and browsers are affected?

Angular: v1.6.8
Angular Material: v1.1.5
Chrome: v63

Is there anything else we should know? Stack Traces, Screenshots, etc.

Playing with the angular-material js file, I found that changing the line 2644 from the compiled js file, inside the MdCompilerService.prototype._createController function, from: angular.extend(invokeCtrl.instance, locals); to angular.extend(ctrl, locals); made it worked.

I also had to add the $mdCompilerProvider.respectPreAssignBindingsEnabled(true); so that line gets executed, because the line angular.extend(invokeCtrl.instance, locals); doesn't bind anything

@Splaktar
Copy link
Contributor

Thank you for your contribution and for looking for a solution for this! However, it is already fixed in master (#10977) and should be out in the 1.1.6 release soon.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants