I am using angular CLI and I am trying to use localStorage for registration component, but this is no working, it says Cannot find name 'localStorage' This is my service
create(user: User) {
return this.http.post('/signup', user, this.jwt(user)).map((response: Response) => response.json());
}
private jwt(user) {
let currentUser = localStorage.setItem('currentUser', user);
if (currentUser && currentUser.token) {
let headers = new Headers({ 'Authorization': 'Bearer ' + currentUser.token });
return new RequestOptions({ headers: headers });
}
}
how can I fix this?
Maybe you have to add lib:dom in your tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "../dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es2016",
"dom"
]
}
}
(source: tsconfig.json)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With