I'm attempting to use the jqLite function element.html directly as a listener for 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
}
};
});
Unfortunately, this approach doesn't seem to work as expected. As a workaround, I had to wrap 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);
});
}
};
});
The second example provided above does work correctly.
I'm puzzled as to why the first example isn't functioning properly. Any insights?
EDIT: I should note that the browser isn't generating any errors. It simply displays an empty element.