Use of symbols '@', '&', '=' and '>' in custom directive's scope binding: AngularJS

MAC picture MAC · Jun 14, 2016 · Viewed 142.1k times · Source

I have read a lot about the use of these symbols in the implementation of custom directives in AngularJS but the concept is still not clear to me.

What does it mean if I use one of the scope values in the custom directive?

What exactly are we doing with the scope here?

I am also not sure whether "scope:'>'" exists in the official documentation or not. It's been used in my project. (The use of "scope:'>'" was an issue in my project and It has been fixed.)

Answer

Aravind picture Aravind · Jun 14, 2016

> is not in the documentation.

< is for one-way binding.

@ binding is for passing strings. These strings support {{}} expressions for interpolated values.

= binding is for two-way model binding. The model in parent scope is linked to the model in the directive's isolated scope.

& binding is for passing a method into your directive's scope so that it can be called within your directive.

When we are setting scope: true in directive, Angular js will create a new scope for that directive. That means any changes made to the directive scope will not reflect back in parent controller.