I am currently working on a custom directive that will activate a specified event when a particular expression evaluates as true. The code below demonstrates how it can be achieved when binding a single value-
<div ng-trigger="value.someBoolean" />
app.directive('ngTrigger', [
"$timeout","$log", function($timeout,$log) {
return {
restrict:"A",
link: function(scope, elem, attr) {
scope.$watch(attr.ngTrigger, function (e) {
if (e) {
$timeout(function() {
elem.triggerHandler('someevent');
});
} else {
$timeout(function () {
elem.triggerHandler('someotherevent');
});
}
});
}
};
}
]);
However, this method fails when binding a more complex expression like -
<div ng-trigger="!value.someBoolean && value.someOtherBoolean" />
I am seeking advice on how to modify this directive to handle complex expressions and ensure that it can detect changes in both parts of the expression simultaneously.