What is the reason for not having one-time binding in Angular -


i have tried googling long time not find valid answer. why there no 1 time binding in angular 2. dont think changedetectionstrategy 1 time binding solution. why did angular team did not consider include feature? did see no performance benefit implementing this. if binding data once titles , headers etc 1 way binding great go right? since have less watchers 1 time binding did ignore it? please let me know.

edit 1 time binding @ property level possible in angular 1 using {{::name}} not included in angular 2. why syntax removed. appreciated

i believe it's because of difference in implementation of change detection mechanism.

in angularjs can dynamically add or remove watchers update dom. example, if have following template:

{{name}} 

you can add watcher:

const unwatch = $scope.$watch('name', () => { updatedom() }); 

what's interesting angularjs returns reference function can call remove watcher dynamically. , angular uses possibility remove watcher after first call 1 time bindings:

const unwatch = $scope.$watch('name', () => { if (!initial) unwatch(); updatedom() }); 

however, in angular mechanism different. code checks bindings generated compiler statically , since "watcher" not added dynamically cannot removed dynamically. generated function performs dom checks called updaterenderer , can read more in article the mechanics of dom updates in angular. binding:

{{name}} 

the generated function have following body:

var _co = _v.component; var currval_0 = _co.name; // read value _ck(_v,1,0,currval_0);    // update dom 

and once generated, function body can't changed.


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -