Shashi
Shashi

Reputation: 11

AngularJS : What is the usage of '=?' in scope of angular directive

I have seen developers using '=?' in angular scope for a directive. Can someone please explain me its usage.

Upvotes: 1

Views: 123

Answers (1)

RiesvGeffen
RiesvGeffen

Reputation: 1589

= or =attr - set up bi-directional binding between a local scope property and the parent scope property of name defined via the value of the attr attribute. If no attr name is specified then the attribute name is assumed to be the same as the local name. Given <widget my-attr="parentModel"> and widget definition of scope: { localModel:'=myAttr' }, then widget scope property localModel will reflect the value of parentModel on the parent scope. Any changes to parentModel will be reflected in localModel and any changes in localModel will reflect in parentModel. If the parent scope property doesn't exist, it will throw a NON_ASSIGNABLE_MODEL_EXPRESSION exception. You can avoid this behavior using =? or =?attr in order to flag the property as optional. If you want to shallow watch for changes (i.e. $watchCollection instead of $watch) you can use =* or =*attr (=*? or =*?attr if the property is optional).

Source (CTRL+F, "=?")

Upvotes: 2

Related Questions