After carefully studying the Angular documentation, I decided to test a basic data binding concept.
Below is an example of the HTML file:
<body ng-app>
<h1>Hello, world!</h1>
<div ng-controller="Ctrl">
<input type="text" ng-model="count" />
COUNT: <span ng-bind="count"></span>
</div>
</body>
Furthermore, here is the Ctrl function in JavaScript:
var i = 0;
function Ctrl($scope) {
$scope.count = i;
inc();
}
function inc() {
i++;
setTimeout(inc, 1000);
}
I initially expected that the "COUNT" in the HTML would continuously update as the variable "i" incremented every second in the JavaScript code.
However, my expectations were not met, and now I'm troubleshooting my code to identify any errors. I also aim to find a suitable example to effectively demonstrate two-way data binding - where changes made to a JavaScript object should reflect in the corresponding HTML elements.