1

I know you can have optional property using a question mark like x:"=?" and then you can check if it is specified by checking if x is undefined or null.

How can I do similar thing for a function? Oftentimes, I want to hide a control if the function is not specified. I have to define another property for this purpose to workaround this problem. I wonder if there is a way to save this extra property.

1

1 Answer 1

2

I found an answer to this question at here. Here is a recap in case somebody is interested:

In directive:

scope: {
    callback: '&'
},
link: function(scope, elem, attrs) {    
  scope.hasCallback = function() {
    return angular.isDefined(attrs.callback);
  }
}

In html:

<a href="" ng-show="hasCallback()" ng-click="callback()">Call me back</a>

I like it very much because it saves me an extra parameter.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.