I may trying to clear my concept on digest loop. I have a small HTML page as :
<!doctype html>
<html>
<head lang="en">
<meta charset="utf-8"/>
<title>Practice</title>
</head>
<body ng-app="myApp">
<div ng-controller="myController">
Enter your text <br>
<textarea rows="5" id="comments" ng-model="commentText"></textarea>
<br>
Type Char:{{ lenghtComment }}
</div>
<script src="https://code.angularjs.org/1.5.0-beta.2/angular.min.js" type="text/javascript"></script>
<script src="prac.js" type="text/javascript"></script>
</body>
</html>
===================================== And small angualr file as :
var myApp=angular.module("myApp",[]);
myApp.controller("myController",["$scope",function($scope){
$scope.commentText="";
/* $scope.lenghtComment=function(){
return $scope.commentText.length;
};*/
$scope.lengthComment=$scope.commentText.length;
}]);
I want to display the count of characters I type in the Text box. Though there are many ways to do so, I wanted to know why the above one does not work. Scope Variable "LenghtComment" is dependent on "commentText", so the digest loops detects a change on "commentText" as the user types in and should then reiterate over watcher-list to ensure if any dependent variable has changed. In this run it should find the change in "lenghtComment" variable and update the app. But the case is not. However if I use the function as commented, it works perfectly great. Please point out gap in my understanding. Thanking you guys in advance.
lenghtCommentbut in your JS file you have the correct spellinglengthComment. Is it wrong in your code or just in your question body?