My code is as simple:
.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 would like to be able to fire when directive expression changes and when it's true or false, but at the moment the alert never happen...
It works only if i do something like:
<div ng-controller="Ctrl">
<span ng-hey="{{x > 3}}"></span>
</div>
which is not what i would like, i would like the directive to execute expressions as for ng-if or ng-hide etc...
Any tip or help appreciated, thanks