Here is my simple code:
.controller('Ctrl', ['$scope', '$timeout', function ($scope, $timeout) {
$timeout(function () {
$scope.x = 5;
}, 2000);
}])
.directive('ngHey', ['$parse', function ($parse) {
return {
'restrict': 'A',
'scope': true,
'link': function($scope, el, atr) {
var go = function () {
if ($parse(atr.ngHey)()) {
alert('oiiiiiii');
}
};
atr.$observe('ngHey', function (val) {
if (val) {
go();
}
});
}
};
}]);
//view.html
<div ng-controller="Ctrl">
<span ng-hey="x > 3"></span>
</div>
I want the directive to fire when the expression changes to either true or false, but currently the alert never appears...
It only works if I use:
<div ng-controller="Ctrl">
<span ng-hey="{{x > 3}}"></span>
</div>
However, this is not what I desire. I want the directive to handle expressions like ng-if or ng-hide...
Any help or tips would be greatly appreciated, thank you