javascript - Benefits of using $scope.foo versus foo.vaue -


in controller, can access inputs values value of dom id instead of setting ng-model directive , binding dom value $scope.

for example, in

<input type="text" ng-model="foo" id=foo> 

we can either use $scope.foo or foo.value in controller. advantage of using $scope in case?

i think main benefits of using ng-model instead of getting value of input id two-way binding. variable ng-model date , can use directly in html or wherever want.

<input type="text" ng-model="foo" id="fooinput" /> <p>ng-model value: <span ng-bind="foo"></span></p> 

if choose approach when value input id lose feature, little bit better performance. because whenever type into, trigger $digest cycle causing angular update watchers , bindings in app see if has changed.

a little demo on plunker.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -