嗨我有一个提示警报,其中有一个登录表单,当用户输入数据,并在完成按钮单击由用户输入的数据应存储为对象,我需要访问它并且能够看到该对象到我的控制台存储提示输入值作为对象
import { Component } from '@angular/core';
import { NavController, NavParams, AlertController } from 'ionic-angular';
@Component({
selector: 'page-login',
templateUrl: 'login.html'
})
export class LoginPage {
//is this right way to store values from input tag
xuser = {
name: '',
email: '',
phone: '',
country: ''
}
constructor(public navCtrl: NavController,
public alertCtrl: AlertController,
) { }
check(){
console.log("hellow");
let alert = this.alertCtrl.create({
title: 'User data',
inputs: [
{
name: 'name',
placeholder: 'Full Name',
type: 'text'
},
{
name: 'email',
placeholder: 'Email',
type: 'email'
},
{
name: 'phone',
placeholder: 'phone Number',
type: 'number'
},
{
name: 'country',
placeholder: 'Country',
type: 'text'
}
],
buttons: [
{
text: 'Done',
handler: data => {
console.log("data given", this.xuser);
}
}
]
});
alert.present();
}
//and i need that data to be stored to my local storage and i need to access it
writeFile(){
var obj = this.xuser;
this.storage.set(obj).then(() => {
this.storage.get(obj).then(() => {
console.log(obj.user.name);
});
});
所以当以往用户点击“检查”警报,窗体打开,我需要将其保存至本地存储和访问再次
什么问题? –
你会得到错误,你在哪里调用writeFile? –
我不能存储用户输入的值,如果我使用html页面,那么我将使用ngmodel,但在提示如何让用户给的价值@GünterZöchbauer –