I have a directive with the following scope:
scope: {
copyObject: '&',
deleteObject: '&'
}
Now, I have a corresponding button in my template which looks like this:
<button ng-click="copyObject()">Copy</button>
However, I would like to hide the button if there's no function applied to copy-object
, for example:
<!-- Should show the copy button -->
<my-directive copy-object="copyObject()"></my-directive>
<!-- Should not show the copy button -->
<my-directive></my-directive>
So I applied the following to my template:
<button ng-click="copyObject()" ng-if="copyObject">Copy</button>
But this does not seem to work, if I check the directives real isolated scope, I notice that, even when the attribute is not entered, the function still exists, so the button is always visible.
Is it possible to detect if a function is bound to the copyObject()
or not? And is it a good practice to do so? I'm not sure if the directive should be aware of the bound function or is this some kind of scope access violation?
An example: http://jsfiddle.net/azchpo5q/ (the second button should not be visible because there is no action bound to it).