I'm creating a bunch of input elements via an *ngFor statement, and on some of them I want to add an data-bv-integer="true" attribute, and on some I don't. Whether it appears or not is based on a property of the *ngFor item.
Is that possible to do?
I tried to add [attr.data-bv-integer]="false" as a test to see if that would remove the item but it doesn't.
This is how you can dynamically add attributes to an HTML element with angular:
[<<attribute>>]="<<condition>> ? '<<if true>>' : '<<if false>>'"
In your case it would be:
[attr.data-bv-integer]="shouldShow() ? 'true' : null"
Note: null will remove the attribute
EDIT: Added "attr." thanks @ConnorsFan
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