Angular
gelöst: Type 'null' is not assignable to type
'string'.ts(2322)
Fehlermeldung Angular/Typescript
(property)
UserComponent.email: string
Type
'string | null' is not assignable to type 'string'.
Type 'null' is not assignable to type 'string'.ts(2322)
|
In der
Angular Codezeile
ngOnInit()
{
this.email = localStorage.getItem('e');
}
|
Lösung: (ist einfach ein Trick)
Am Ende der Anweisung ein Ausrufezeichen setzen. Das bedeuted,
es wird nur ausgeführt, wenn der rechte Wert nicht Null ist
ngOnInit()
{
this.email = localStorage.getItem('e')!;
}
|