The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

New in Angular 1.3 - bindToController

New in Angular 1.3 - bindToController

4:10
If you are using the "controller as" syntax, and you should be using the "controller as" syntax, you will want it to be **consistent** in your Angular state modules as well as your Angular component directives. With the `bindToController` property on the directive definition object, this is easy to accomplish.
Watch this lesson now
Avatar
egghead.io

If you are using the "controller as" syntax, and you should be using the "controller as" syntax, you will want it to be consistent in your Angular state modules as well as your Angular component directives. With the bindToController property on the directive definition object, this is easy to accomplish.

Avatar
Rick

Hi,

Just playing with this and I'm wondering how, if I use a controller as a replacement for the link function, is there a way to get at the element and attributes as well in the controller? Or, do I need a separate link function to do that?

Thanks.

In reply to egghead.io
Avatar
Joel

is there a way to get at the element and attributes as well in the controller? Or, do I need a separate link function to do that?

Yup! You can inject them as $element, $attrs - so outside of simple use cases, it makes a lot of sense to just use a controller. Makes testing much easier!

In reply to Rick
Avatar
Rick

Right! of course! Thank you. :)

In reply to Joel
Avatar
Greg

nice snippet!

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?