This is part of an evaluation of Ionic for me and to be honest it just feels a bit flaky. I have ‘fixed’ my issue, but don’t understand why what I did first time around doesn’t work… Maybe this is some form of noobie error but I don’t think so. I think the function names are pretty obvious but that isn’t the issue anyway.
I initialize a user details form like this:
ngOnInit() {
this.userDetailsForm = this.formBuilder.group({
... some stuff
_Address: [], // This is a holding string value for the pop over form.
... more stuff
});
this.userService.getUserServer().subscribe (user => {
this.userDetailsForm.patchValue(user); // Note the _Address doesn't exist in the user obj.
this.userService.saveUserStore(user);
this.userdata = user;
this.address = new Address(this.userdata.Address); // preserve original address data
this.userDetailsForm.value._Address = this.address.fullAddressString();
},
error => this.helper.showAlert('We cant connect to the server at the moment msg is:' + error)
);
The _Address value is to represent the address as a single string which is completed in a separate Ionic-popover (which all works just fine).
However in the form, with the Address string value like this:
<ion-item>
<ion-label position="fixed">Address:</ion-label>
<ion-input type="text" (click)="getAddress($event)" formControlName="_Address">{{ userDetailsForm.value._Address }}</ion-input>
</ion-item>
It doesn’t work in the initialization part. It DOES work when I update it from the popover code.
If however, I change it to this:
<ion-item>
<ion-label position="fixed">Address:</ion-label>
<ion-input type="text" (click)="getAddress($event)" formControlName="_Address">{{ addressString }}</ion-input>
</ion-item>
… and set the ‘addressString’ value in the ngOnInit function like this instead:
// originally - this.userDetailsForm.value._Address = this.address.fullAddressString();
this.addressString = this.address.fullAddressString();
It initializes and displays just fine.
If I log the value of the form _Address, it is also just fine. Just not displayed on initialization.
Many thanks.