Reputation: 545
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?
Upvotes: 0
Views: 97
Reputation: 175
If your most of the components are not using 'problemBinding', make it optional otherwise it will create watch for that binding in spite of being used. Can refer angular docs.
Upvotes: 1
Reputation: 48968
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
Upvotes: 2