I'm trying to omit an attribute with ngIf
, or something similar in Angular:
<input type="text" maxlength="5" class="form-control-mat"
*ngIf="recomendacion!=undefined" [placeholder]="recomendacion" >
This is what I have right now, but instead of omitting the attribute placeholder
, it skips the entire element.
Is it possible to apply something similar that works on attributes?
The directive
ngIf
manages whether or not the entire element appears, so the element appears or not depending on the value ofrecomendacion
.Below I show how to use
recomendacion
so that the attribute appears only when the variable is defined:You can refer to the Angular documentation :
In Spanish:
You can condition an attribute within it.
In the example that I give you, what we do is set the attribute
placeholder
if there is a recommendation, otherwise we return anull
, which disables the attribute.For the conditional, in case you have never used them:
The best thing about this is that it lets you condition the value of the attribute, very useful for working with css, classes and element states.