I'm using @HostBinding to bind the results of a function to the host element's visible attribute:
@HostBinding('attr.visible')
private get visibleAttr(): any {
return this._visible ? '' : null;
}
The function name seems redundant because nothing else will ever call this function. I tried to declare it like an anonymous lambda function but it didn't work:
@HostBinding('attr.visible') (() => {
return this._visible ? '' : null;
})
Is there a way to declare this function anonymously, or at least with a lambda? Or does the Angular framework depend on it being named?
@HostBinding is a decorator and needs a valid member to decorate. If your 2nd code example
(() => {
return this._visible ? '' : null;
})
on it's own was a valid member it could work but this is not valid typescript (or javascript) for a member declaration. As such it can't work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With