Reputation: 117
I want to get value from local storage and used that value in my request URL to get customer details in Angular 6.
login.component.ts
OnLogin(){
this.loginService.userLogin(this.username,this.password)
.subscribe(
data => {
localStorage.setItem('AccountNo',data.AccountNo);
}
}
login.service.ts:
getAccountNo(){
return localStorage.getItem('AccountNo');
}
checkout.service.ts:
login1 = this.loginService.getAccountNo();
async getAddress() {
const address = await this.httpClient.get<Customer[]>('http://localhost:49422/api/customer/' + 'login1' +'/profile/', { withCredentials: true })
.toPromise();
return address;
}
After the customer login, their details are maintained in local storage. I want to get the account number value from local storage and to be used in the URL in checkout service. How to achieve this? Is it possible to get the value from request header using interceptors? If it possible then how should achieve this?
Upvotes: 2
Views: 4213
Reputation: 222582
You should use the same key
which you have used for retrieval also
return localStorage.getItem('account_no');
EDIT
you need to use just login1
instead of 'login1.AccountNo'
in your request
Upvotes: 3
Reputation: 3483
Can use like that,
getAccountNo(){
return localStorage.getItem('account_no');
}
Upvotes: 3