Angular how to use disabled in a matInput input?

Asked

Viewed 72 times

0

I have my HTML:

<form class="needs-validation" novalidate [formGroup]="form">
 <div class="form-row">
  <div class="col-md-4 mb-3">
    <label for="nome">Nome</label>
     <input matInput type="text" class="form-control" 
         id="nome" formControlName="nome" />
     <app-campo-control-erro [control]="form.get('nome')" 
         label="Nome">
     </app-campo-control-erro>
   </div>
    

however in input one disabled=isMaps, does not work, how to disable the input?. (Angular Version 8.0).

controller:

if(diretorio.nome == "Mapas") {
    this.isMaps = true;
}
  • 1

    If you’re using a reactive form, you wouldn’t have to validate it on the TS?!

1 answer

0


According to this new version of Angular 8.0 Actually disabled input fields should stay in . ts

HTML continued like this:

<form class="needs-validation" novalidate [formGroup]="form">
 <div class="form-row">
  <div class="col-md-4 mb-3">
    <label for="nome">Nome</label>
     <input matInput type="text" class="form-control" 
         id="nome" formControlName="nome" />
     <app-campo-control-erro [control]="form.get('nome')" 
         label="Nome">
     </app-campo-control-erro>
   </div>

My controller.ts was like this once:

if(diretorio.nome == "Mapas"){
  this.isMaps = true;
  this.form.get('nome').disable();
}
  

Question answered in OS https://stackoverflow.com/questions/55569844/disable-input-on-angular-form

Browser other questions tagged

You are not signed in. Login or sign up in order to post.