Reputation: 3657
In my directive I use expression:
return {
restrict: 'E',
scope: {
func: "&?"
},
controller: 'directiveCtrl',
controllerAs: 'vm',
bindToController: true
}
function directiveCtrl() {
var vm = this;
vm.isFunc = angular.isDefined(vm.func) || false;
}
How to check if func
is defined? Now it's always defined:/
<my-directive></my-directive>
<my-directive func='myFunc()'></my-directive>
Upvotes: 0
Views: 66
Reputation: 1835
I think this should work:
function directiveCtrl($scope) {
var vm = this;
vm.isFunc = angular.isDefined($scope.func) || false;
}
Upvotes: 0
Reputation: 1365
You can do it in the link function of the directive as below:
return{
restrict: 'E',
scope: {
func: "&?"
},
controller: 'directiveCtrl',
controllerAs: 'vm',
bindToController: true,
link:function(scope,element,attrs){
if(attrs.func) {
attrs.$observe('func', function(value) {
console.log(value);
});
}
}
Upvotes: 2