How to insert value in Ionic input 3

Asked

Viewed 264 times

0

Good afternoon guys, I have a question and so far I have not found any solution, I need to pass a value from the database to the input on the login screen, but I did not find how to do this. My code responsible please the form is this one:

  <form class="login-form auth-form" [formGroup]="formulario" (ngSubmit)="login()">
    <ion-item>
      <ion-label floating>Informe seu login</ion-label>
      <ion-input type="text" formControlName="login" name='login'></ion-input>
    </ion-item>
    <show-hide-container>
      <ion-item>
        <ion-label floating>Informe sua senha</ion-label>
        <ion-input type="password" formControlName="password" name='password' show-hide-input></ion-input>
      </ion-item>
    </show-hide-container>
    <ion-item>
      <ion-label>Lembrar login</ion-label>
      <ion-checkbox color="primary" formControlName="remember" name="remember" checked='false'></ion-checkbox>
    </ion-item>
    
    <button ion-button block class="auth-action-button login-button" name="buttonSubmit" type="submit" [disabled]="!login.valido">Entrar</button>
    
  </form>

The function I want to do to change the value of the field would be inside ngOnInit(),I already have the variable with the value but I can not insert this value inside the input "Login", I appreciate your help from now.

  • 1

    But what the problem is, it’s not just making Binding data into input?

  • Missed I figure out what action to do, searched by Binding date here and finally managed to do, thank you very much!

1 answer

0


With the help of Leandrade, I managed to solve my problem, I put in the input code ngModel, getting like this:

<ion-input [(ngModel)]="myvariable" type="text" formControlName="login" name='login'></ion-input>

then in ts file, I declared in export the variable "myvariable" and in the code I put

ngOnInit() {
    this.myvariable =  this.getLastLogged();
  } 

that way I was able to add to the input the value I wanted!

Browser other questions tagged

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