Manipulating data in Ionic 2

Asked

Viewed 389 times

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?

  • The value is being passed, but I need to get the separate value of each controlname within this updateUser function()

  • Add an attribute for each value in your PerfilPage and do something like this.displayname = this.updateUser.value.displayname and this.email = this.updateUser.value.email. That’s what you need?

No answers

Browser other questions tagged

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