this.profileFormStageOne.get('nationality').valueChanges.subscribe(val => {
if (val && val === 'Other') {
let alert = this.alertCtrl.create({
title: 'Your Nationality',
inputs: [
{
name: 'nationality',
placeholder: 'Your Nationality e.g. Brazilian',
},
],
buttons: [
{
text: 'Update Nationality',
handler: data => {
this.manualNationality = data.nationality;
console.log(this.manualNationality);
},
},
],
});
alert.present();
}
});
不过,我也使用ngOnChanges()来修补以下形式的值:
/**
* Get initial form values
* Needs to run from ngOnChanges because User in an input & is not ready in constructor
*/
ngOnChanges() {
if (this.User) {
const profile: Profile = this.User.profile;
this.profileFormStageOne.patchValue({
nationality: profile.nationality,
问题是,如果国籍字段已设置为“其他”,则在初始呈现(在修补程序值期间)上调用此函数。