I'm trying to pass the jqLite function element.html directly as a listener of a watcher:
angular.module('testApp', []).directive('test', function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
scope.$watch('someVariable', element.html); // <-- Passing the function handle as listener
}
};
});
However this does not work for some reason, so as a workaround I wrapped the listener in a function:
angular.module('testApp', []).directive('test', function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
scope.$watch('someVariable', function (newValue) {
element.html(newValue);
});
}
};
});
This second example works.
I don't understand why the first example is broken. Any ideas?
EDIT: I forgot to mention, the browser does not give me any errors. It just shows me an empty element.