Utilizing the <?
symbol allows the controller to alter the value of the variable intended to be bound, only if that variable does not exist.
When optional bindings are absent, they can be adjusted in the controller. However, once a value is supplied to the component, it becomes immutable.
In contrast, non-optional bindings remain unchangeable. If these bindings are missing, they default to being undefined
and cannot be altered in any way.
For instance, consider the following scenario:
bindings: {
nameOptional: '<?',
nameRequired: '<'
}
Attempting to modify
$ctrl.nameRequired = 'something else'
in the controller will not update the view. On the other hand, modifying
nameOptional
is possible under one condition: the absence of
name-optional
being passed to the component grants control over the variable to the controller.
To gain a better grasp of this concept, you can review this fiddle.
It's important to note that for simplicity, we are using a string which is passed by value. When dealing with objects, their properties remain modifiable under normal circumstances.