hey kartik,
Before you move in to the topic do check- $watch and watch listener function first.
$watch() function is used to watch the changes of variables in $scope object and watch listener is a function that is executed automatically when variable changes its value at its scope.
Generally,there are four types of $watch(). They are:-
1.) $watch-reference watch:
"o" is a object has the property contain in it. For object "o" watch listener function is created and the event will fire only if object "o" will assign to other object.
[Note]: No changes will occur if object's "o" property is modify.
2.) $watch with "true"- Equality watch:
Equality watch is same as Reference watch but the only difference is that if you provide "true" value in watch listener function at the end it will allow event to be fire even object "o" property is chnaged.
3:) $watch group:
watch group function is used to manipulate watch scope of the variable that is not binded to no scope. Simply we can use array of several other scope variable
4:)Collection watch:
It is used to watch array. It can also be used to detect modification to an array (i.e adding or deleting). However to achieve this use Equality watch.
here scope emp contains data, However if we add items to it then watch function event will fire automatically if we push data to emp array
{Note}: It will not execute if any modification of arrays data will occur.(executed only if any add or deletion will take place in an array).