Angular Fiddle
HTML
<script type="text/javascript" ng:autobind
src="http://code.angularjs.org/0.9.16/angular-0.9.16.js"></script>
<input name="testip" />{{testip}}
<my:watch exp="name"/>
JavaScript
function MainCntl() {
this.testip = 'init';
}
angular.widget('my:watch', function(compileElement) {
return function(linkElement) {
// watch using string - evaluated as angular expression
this.$watch('testip', function(value) {
alert('1: ' + value);
});
// the same watcher using function and closure
var currentScope = this;
this.$watch(function() {
return currentScope.testip;
}, function(value) {
alert('2: ' + value);
});
};
});