Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the question mark do in an Angular isolate scope binding?

I have read a lot of articles explaining the difference between @, = and &. I've seen a lot of people using =? in their code. What does this mean?

Unfortunately, I can't seem to search on Google or SO for an answer because search engines ignore special characters.

like image 708
jonhobbs Avatar asked Apr 14 '15 23:04

jonhobbs


People also ask

What is @? In angular directive scope?

These prefixes are used to bind the parent scope's methods and properties to the directive scope. There are 3 types of prefixes in AngularJS: '@' – Text binding / one-way binding. '=' – Direct model binding / two-way binding.

Which symbol is used to represent data binding in angular?

Property binding is used to bind the data from property of a component to DOM elements. It is denoted by []. Let's understand with a simple example.

Which binding strategy symbol in isolated scope means passing this attribute?

All three bindings are ways of passing data from your parent scope to your directive's isolated scope through the element's attributes: @ binding is for passing strings. These strings support {{}} expressions for interpolated values.

What is =? In AngularJS?

= 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.


1 Answers

The ? makes the property optional. Otherwise, you'll get NON_ASSIGNABLE_MODEL_EXPRESSION where Angular is looking for a property that doesn't exist.

From the docs:

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.

https://docs.angularjs.org/api/ng/service/$compile#-scope-

like image 60
SomeKittens Avatar answered Nov 16 '22 02:11

SomeKittens