Problem
For instance, say you have an input text field called email
and you want to trigger or execute some code as soon as a user starts to type in their email.
This can be achieved by using $watch
function in the controller.
function MyCtrl($scope) {
$scope.email = '';
$scope.$watch('email', function (newValue, oldValue) {
if ($scope.email.length > 0) {
console.log('User has started writing into email');
}
});
}