I have this simple snippet:
HTML:
<div ng-app="myApp" ng-controller="SampleController">
<p>{{val1}}</p>
<p>{{val2}}</p>
<input type="button" value="Update" ng-click="update()" />
</div>
Javascript:
var app = angular.module('myApp', []);
app.controller('SampleController', ['$scope', function($scope) {
$scope.val1 = "Not updated";
$scope.val2 = "Not updated";
$scope.update = function () {
$scope.val1 = "Updated outside!";
setTimeout(function () {
$scope.val2 = "Update inside!";
}, 1);
};
}]);
snippet also in jsfiddle.
If I click in the update button only the value val1 is updated in the html. How to fix that? But most importantly, why is this happening?
PS: setTimeout is just a simplification of the problem. In fact the question is about any custom components that has callback functions.