Reputation: 11
I have seen developers using '=?' in angular scope for a directive. Can someone please explain me its usage.
Upvotes: 1
Views: 123
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 theattr
attribute. If noattr
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 ofscope: { localModel:'=myAttr' }
, then widget scope propertylocalModel
will reflect the value ofparentModel
on the parent scope. Any changes toparentModel
will be reflected inlocalModel
and any changes inlocalModel
will reflect inparentModel
. 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