Model and view update through angularJS

69 views
Skip to first unread message

Ron Likvornik

unread,
Feb 24, 2014, 4:43:46 PM2/24/14
to ang...@googlegroups.com
Someone told me that in Angular when i update something in the model the view should be updated automatically. And when i update something in the view the model should be updated automatically.
I can see why the view updated automatically when i change the model but i cannot see the opposite.
Can you give me an example for that?Thanks.

Sander Elias

unread,
Feb 25, 2014, 12:13:56 AM2/25/14
to ang...@googlegroups.com

Luke Kende

unread,
Feb 25, 2014, 1:57:12 AM2/25/14
to ang...@googlegroups.com
If you just need to "see" that the value is updating on the $scope, use an ng-click on a button to call a function and console.log() the value after you've changed it in the view.

<div ng-controller="myCtrl">
<input ng-model="item.text">
<button ng-click="logText">Log it</button>
</div>

function myCtrl(){
  $scope.item = { text: '' }

  $scope.logText = function(){
    console.log($scope.item.text)
Reply all
Reply to author
Forward
0 new messages