flow:
- User submits a form with some data, some optional fields that the user didn't fill are saved in mongo as 'null'.
- Later on, user decides to edit that form.
- Service grabs the form and displays it to the user.
- The form input boxes displays 'null' because in step 1 he didn't fill them.
So, I created a pipe:
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({
name: 'transformNull'
})
export class TransformNull implements PipeTransform {
transform(value) {
if (value == null) {
return null;
}
}
Then, in HTML I tried to break down the ngModel:
[ngModel]="user.extraInfo | transformNull" (ngModelChange)="user.extraInfo.value=$event"
this caused this error:
Cannot set property 'value' of undefined TypeError: Cannot set property 'value' of undefined
I tried to delay the page load with an *ngIf="isDataAvailable", the error went away, the user can save the form, the value gets stored to mongo but when he refreshes the page, the input box is empty.
Then i removed the *ngIf, added elvis operators but the value error comes back.
I'm using zone.js v0.7.4, tried with 0.7.2 and 0.7.5 but no luck.
What am I missing here?