Search code examples
angularjsangularjs-directiveangularjs-scope

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.


Solution

  • 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-