Por medio de una variable también podemos quitar el input de nameCompany en la vista para que cuando seleccione customer no se lo muestre.
this.typeField.valueChanges.subscribe(value => {
if (value === 'company') {
this.companyNameField.setValidators([Validators.required]);
this.showCompany = true;
} else {
this.companyNameField.setValidators(null);
this.showCompany = false;
}
this.companyNameField.updateValueAndValidity();
});
<div *ngIf="showCompany" class="row">
<div class="col-xs">
<mat-form-field>
<mat-label>Company Name</mat-label>
<input placeholder="company" formControlName="companyName" matInput type="text"/>
</mat-form-field>
</div>
</div>
¿Quieres ver más aportes, preguntas y respuestas de la comunidad? Crea una cuenta o inicia sesión.