I have a component repeating quite a few times and would like to avoid excessive watching.
angular
.module('myModule')
.component('component', {
template: '',
bindings: {
code: '@',
problemBinding: '<',
},
controller: componentController,
});
Each <
binding seems to create a watcher despite the fact that most of the components are not using problem-binding
argument in the html. This is demonstrated in this plunkr where each new <
binding creates as many watchers as the component is being repeated.
Is there a way to use problemBinding
so that it creates a watcher for the component if and only if the argument is being used?
angular
.module('myModule')
.component('component', {
template: '',
bindings: {
code: '@',
problemBinding: '<?',
},
controller: componentController,
});
All 4 kinds of bindings (@
, =
, <
, and &
) can be made optional by adding ?
to the expression. The marker must come after the mode and before the attribute name.
For more information, see