-
-
Notifications
You must be signed in to change notification settings - Fork 241
Description
I'm using Nativescript + Angular
| nativescript │ 3.4.3 │ 3.4.3 │ Up to date │
│ tns-core-modules │ 3.4.1 │ 3.4.1 │ Up to date │
│ tns-android │ 3.4.2 │ 3.4.2 │ Up to date │
I'm using a code which creates a custom ngModel
value using the ControlValueAccessor
interface .
As you can see I have 2 TextFields and a json showing the model value.
This is how I activate the component with value :
home.component.ts
export class HomeComponent {
dataModel = {
a:1,b:2
};
...
}
home.component.html
<StackLayout >
<app-flag [(ngModel)]="dataModel"></app-flag>
</StackLayout>
— This is the actual component markup code :
flag.component.html
<GridLayout rows="auto,auto,auto" columns="*" >
<TextField [(ngModel)]="innerValue.a" row="0" ></TextField>
<TextField [(ngModel)]="innerValue.b" row="1"></TextField>
<Label textWrap="true" text="{{innerValue | json}}" row=3></Label>
</GridLayout>
flag.component.ts
export class FlagComponent implements ControlValueAccessor {
innerValue: { a: 1, b: 2 }
writeValue(value: any) {
this.innerValue = value;
}
...}
This code works fine , and does show the values in json. But the problem is that at t=0 , there is an error :
ERROR TypeError: Cannot read property 'a' of null
After testings - it seems that at first - the value in writeValue
is null.
Question
Something is not right here. Even if there's a delay in writeValue
values - it still has a public property with initial values :
So how come it's null
?
BTW - in native angular it doesn't happen - same code :