1
I am using Ionic 2 for the development of an application, I would like to know how I can use the values sent from a form within a method.
I have the following form:
<form [formGroup]="updateUser" (ngSubmit)="UpdateUser(displayname, email)" #upForm="ngForm">
<ion-list>
<ion-item>
<ion-label floating>Nome</ion-label>
<ion-input type="text" name="displayname" formControlName="displayname"></ion-input>
</ion-item>
<ion-item>
<ion-label floating>E-mail</ion-label>
<ion-input type="text" name="email" formControlName="email"></ion-input>
</ion-item>
</ion-list>
<button ion-button block [disabled]="updateUser.invalid">Atualizar Dados</button>
And the following method within my profile.ts:
import { Component } from '@angular/core';
import { NavController, NavParams, LoadingController } from 'ionic-angular';
import { Validators, FormBuilder } from '@angular/forms';
import { AuthProvider } from '../../providers/auth';
import * as firebase from 'firebase';
@Component({
selector: 'page-perfil',
templateUrl: 'perfil.html'
})
export class PerfilPage {
perfis: any;
updateUser: any = {};
constructor(public formBuilder: FormBuilder, public navCtrl: NavController, public navParams: NavParams, private auth: AuthProvider, private loadingCtrl: LoadingController) {
auth.getUserData().then(data =>{
this.perfis = data;
this.perfis = Array.of(this.perfis);
})
this.updateUser = this.formBuilder.group({
displayname: ['', Validators.required],
email: ['', Validators.required]
})
}
UpdateUser(){
console.log(this.updateUser.value);
}
}
I need to take the values of Display Name and Email within this method, so I can only see in the console, and I need to use the values within the method
I don’t understand, the value of your form is not already being passed to the method through the property
this.updateUser? What are you trying to do?– Marcelo de Andrade
The value is being passed, but I need to get the separate value of each controlname within this updateUser function()
– user76564
Add an attribute for each value in your
PerfilPageand do something likethis.displayname = this.updateUser.value.displaynameandthis.email = this.updateUser.value.email. That’s what you need?– Marcelo de Andrade