這是我的服務
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root',
})
export class LocalStorageService {
constructor() {}
setItem<T>(key: string, object: T) {
localStorage.setItem(key, JSON.stringify(object));
}
getItem(key: string) {
return JSON.parse(localStorage.getItem(key)!);
}
removeItem(key: string) {
localStorage.removeItem(key);
}
isExist(key: string) {
if (JSON.parse(localStorage.getItem(key)!)) {
return true;
} else {
return false;
}
}
}
這是我的代碼
GetUserById() {
this.authService.GetUserById(localStorage.getItem('Id')).subscribe(
(response) => {
this.user = response.data;
this.editProfileForm.setValue({
Id:this.user.Id,
FirstName: this.user.FirstName,
LastName: this.user.LastName,
Email: this.user.Email,
password: '',
});
},
(responseError) => {
this.toastrService.error(responseError.error);
}
);
}
所以“字串”型別的引數不能分配給“數字”型別的引數。這是錯誤,所以我怎樣才能獲得更多資訊
this line is error >>>>>>>>> this.authService.GetUserById(localStorage.getItem('Id')).subscribe <<<<<
uj5u.com熱心網友回復:
Number(localStorage)
Number(this.authService)
// 'Id',JSON.stringify(this.Id)
this.authService.GetUserById(Number(localStorage.getItem("userId"))).subscribe(
(response) => {
this.user = response.data;
console.log(response.data)
沒有人回答,但我找到了
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/485160.html
上一篇:jsconfig路徑別名不起作用
