(function () {
'use strict';
angular.module('myApp', [])
.controller('DIController', myFunction);
DIController.$inject = ['$scope', '$filter'];
function myFunction($scope, $filter) {
$scope.name = "Obama Donald";
$scope.upper = function () {
var upCase = $filter('uppercase');
$scope.name = upCase($scope.name);
};
}
})();
Angular defines a concept of a so called digest cycle. This cycle can be considered as a loop, during which Angular checks if there are any changes to all the variables watched by all the $scopes. So if you have $scope.myVar defined in your controller and this variable was marked for being watched, then you are explicitly telling Angular to monitor the changes on myVar in each iteration of the loop.
This "digest" is also called "dirty checking", because, in a way, it scans the scope for changes. I cannot say if it's for better or for worse than observable pattern. It depends on your needs.
What is dirty checking?
The process of checking every watch to detect the changes, is called dirty checking. There could be two scenarios:
Note: Dirty checking will check anything changes in $scope variable and update it to the DOM. This done by angular js, you can also implement dirty checking by your own.
-
First Scenario
- Get a watch from list
- Check whether item has been changed
- If there is no change in item then
- No Action taken, move to next item in watch list
-
Second Scenario
- Get a watch from list
- Check whether item has been changed
- If there is Change in an item, DOM needs to be updated, return to digest loop
Note: Dirty checking will check anything changes in $scope variable and update it to the DOM. This done by angular js, you can also implement dirty checking by your own.