2017-11-29 4 views
-2

나는ionic 2 입력에서 기본값을 설정하는 방법은 무엇입니까?

address.html 파일 코드

<ion-item> 
<ion-label floating>{{'address.email'|translate}}</ion-label> 
     <ion-input type="text" formControlName="user_email"></ion-input> 
    </ion-item> 

default mail like [email protected]

adderss.ts

ionViewDidEnter() { 
    if (this.isCache) this.getData(); 
    else this.isCache = true; 
} 
getData() { 
    this.storageMul.get(['login', 'useBilling', 'user']).then(val => { 
     if (val['login']) this.login = val['login']; 
     if (val['useBilling'] == false) this.useBilling = false; 
     else this.useBilling = true; 
     if (val['user']) { 
      this.data = val['user']; 

     } 
     this.reset(); 
    }); 
} 
reset() { 
    this.formAddress.patchValue({ 
     billing_first_name: this.data["billing_first_name"], 
     billing_address_1: this.data["billing_address_1"], 
     billing_phone: this.data["billing_phone"], 
     user_email: this.data["user_email"], 
     shipping_first_name: this.data["shipping_first_name"], 
     shipping_address_1: this.data["shipping_address_1"], 
    }); 

도와주세요 .. 이온 입력의 기본값을 설정하려면하시기 바랍니다 도와주세요 !!

+0

작동하지 않는 기능은 무엇입니까? 어딘가에 문제가 있습니까? 어떤 오류? – Alex

+0

정확히 무엇을하려고하는지 정확히 이해하지 못합니다 ... – mix3d

답변

1

당신은 정상 [(ngModel)] 바인드 함께 할 것입니다. 특정 값으로 변수를 설정합니다 당신의 타이프 라이터 내부

<ion-label floating>{{'address.email'|translate}}</ion-label> 
    <ion-input type="text" [(ngModel)]="user_email"></ion-input> 
</ion-item> 

페이지가로드 될 때

* 사용자가 값을 화면에 진입이 방법

constructor() { 
    this.user_email = '[email protected]'; 
} 

을 .component.ts 기본값이되며 사용자가 해당 값을 계속 업데이트 할 수 있습니다.

+0

나는 이해할 수 없다 ... 선생님 ...이 코드에 의해 기본값을 넣는 방법은 무엇입니까' user_email : [ ''],' –