I want to create a bunch of generic components (angular 1.5) with multiple
optional bindings that would be used inside multiple applications.
I am afraid it will create a lot of unnecessary watchers for an application
that doesn't use the most of optional bindings.
Example:
*Component declaration:*
let dateRangeComponent = {
bindings: {
label: '@',
name1: '@',
name2: '@',
model1: '>?',
model2: '>?',
extra1: '>?'
},
template: `<div ng-if="$ctrl.model1>stuff</div>
<div ng-if="$ctrl.model2>stuff</div>
<div ng-if="$ctrl.extra1>stuff</div>`};
*Component Use:*
<date-rage-component label="Pretty Date" name1="Start" name2="end"/>
My question is if it is possible to automatically unwatch all the stuff
related with the unused optional bindings, knowing they are undefined in
compile time?
For instance, imagine I want to use a component in my application where it
doesn't need any of the optional Binding, angular would create a lot of
unnecessary watchers to keep the ng-if updated, when we know they will
always be false.
Am I doing an early performance optimization when not needed or
misunderstanding some concept?
I though in creating a costum directive to take advantage of the lazy
transclude compilation in angular 1.5
Something like this (pseudo-code, not tested):
<optional-binding-once ng-if="::attrs.model1">
<div ng-if="::attrs.model1">
stuff
</div></optional-binding-once>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.