I followed some tutorials to create angular directives. In the isolate scope, some tutorials define scope like this:
scope: {
model: '=?',
data: '@?'
}
Meanwhile, some tutorials define scope without question mark like this:
scope: {
model: '=',
data: '@'
}
Can anybody explain me the difference or the purpose of these with examples? Thank you.
I followed some tutorials to create angular directives. In the isolate scope, some tutorials define scope like this:
scope: {
model: '=?',
data: '@?'
}
Meanwhile, some tutorials define scope without question mark like this:
scope: {
model: '=',
data: '@'
}
Can anybody explain me the difference or the purpose of these with examples? Thank you.
Share Improve this question edited Apr 27, 2019 at 18:30 Daniel Cottone 4,48029 silver badges39 bronze badges asked Jul 23, 2015 at 13:47 ShaohaoShaohao 3,5117 gold badges27 silver badges45 bronze badges1 Answer
Reset to default 14The &
, @
, and =
symbols are used to define the bindings (one-way, bi-directional, etc) for isolated scope objects, as you already know. Here is a pretty thorough tutorial on how all this works.
The ?
symbol is used to indicate that the parent scope property to which the isolated scope binding refers to is optional. This means that if for some reason the parent scope property doesn't exist, then your application will continue to run without throwing the NON_ASSIGNABLE_MODEL_EXPRESSION exception.