I have seen developers using '=?' in angular scope for a directive. Can someone please explain me its usage.
1 Answer
=or=attr- set up bi-directional binding between a local scope property and the parent scope property of name defined via the value of theattrattribute. If noattrname 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 propertylocalModelwill reflect the value ofparentModelon the parent scope. Any changes toparentModelwill be reflected inlocalModeland any changes inlocalModelwill 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=?attrin 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=*?attrif the property is optional).
Source (CTRL+F, "=?")
5 Comments
NON_ASSIGNABLE_MODEL_EXPRESSION error.=? expression is new for me too, I don't know anything about it.=?, hope that answers your question a bit more.
=?means optional two way binding. Without the?if you didn't provide an attribute in the DOM it would throw an exception.