ionic2 angular2如何将输入组件的值设置为存储中的元素

时间:2017-10-03 07:28:29

标签: angular input ionic2 local-storage

我是ionic2 angular2的新手,我有一个从用户请求地址的应用程序,我想确保如果用户之前已输入该地址并且他想使用该应用程序发出另一个请求,则提交的地址为第一个请求会自动设置到输入组件中,我该怎么办呢?

这是我的服务地址

<div id="serviceAddress" *ngIf = "showServiceAddress">
<h4>  Service address</h4>
<ion-list>

  <ion-item>
    <ion-label floating>Addreess</ion-label>
    <ion-input type="text" name= "address" #address [(ngModel)]="addValue"></ion-input>
  </ion-item>

  <ion-item>
    <ion-label floating>Landmark</ion-label>
    <ion-input type="text" name="landmark" #landmark></ion-input>
  </ion-item>

    <ion-item>
    <ion-label floating>Contact</ion-label>
    <ion-input type="text" name="contact" #contact></ion-input>
  </ion-item>


    <ion-item>
      <ion-label>Date</ion-label>
      <ion-datetime displayFormat="MMM DD, h:mm A" [(ngModel)]="myDate"></ion-datetime>

    </ion-item>


    <ion-item>
      <ion-label>Time</ion-label>
      <ion-datetime displayFormat="h:mm A" pickerFormat="h mm A" [(ngModel)]="event.timeStarts" name="protime" #protime></ion-datetime>
    </ion-item>

</ion-list>



<button ion-button icon-right float-right (click)=goToSubscriptionPage()>
 Next
  <ion-icon name="arrow-round-forward"></ion-icon>
</button>

</div>

这是我的ts文件

import { Component, ViewChild } from '@angular/core';
import { NavController, AlertController } from 'ionic-angular';
import { SubscriptionPage } from '../subscription/subscription';
import { RequestPage } from '../request/request';
import {Http, Headers} from '@angular/http';
import { Storage } from '@ionic/storage';

@Component({
  selector: 'page-electrical',
  templateUrl: 'serviceaddress.html'
})
export class ServiceaddressPage {

@ViewChild("address") address;
@ViewChild("landmark") landmark;
@ViewChild("contact") contact;

data:string;
addValue:any;

 public event = {
    month: '2017-09-19',
    timeStarts: '07:43',
    timeEnds: '2040-09-20'
}

 FQNewBuilding(){
 this.storage.get('address').then((value) => {
var addressTxt = value
console.log(addressTxt)
});

 this.storage.get('landmark').then((value) => {
 var landmarkTxt = value
 console.log(landmarkTxt)
});
 this.storage.get('contact').then((value) => {
  var contactTxt = value
  console.log(contactTxt)
});

this.storage.get('address').then((value) => {
var addressTxt = value 

this.addValue = addressTxt});

 } 

请注意,我删除了与问题无关的部分代码。

问题是地址的本地存储值未设置为我的输入ngModel的addValue

0 个答案:

没有答案