Say I have an angular component ie <this-thing></this-thing>
which does it's thing.
Now I want to add something extra to it, ie <this-thing glows></this-thing>
I would like the component to change a little if the glow attribute is there.
I have managed to do it via <this-thing [glows]="true"></this-thing>
and in the component I have
@Input() public set glows(value: boolean) {
console.log(value);
}
But that becomes too verbose.
If glows attribute is not on the component, then it's false and if it is, then true.
Is there a better way to acheive this?
Thanks for looking.
use @Attribute
and @optional
in constructor see the docs
constructor(@Optional() @Attribute('glow') glow: any) {
console.log(glow)
console.log(glow==undefined)
}
<hello glow></hello> //give you '',false
<hello></hello> //give you null,true
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