1
authentication.service.ts參數類型 '用戶' 的是不能分配給類型 '字符串'
import {Injectable} from '@angular/core';
import {Router} from '@angular/router';
export class User {
constructor(
public email: string,
public password: string
) { }
}
var users = [
new User('[email protected]','adm9'),
new User('[email protected]','a23')
];
@Injectable()
export class AuthenticationService {
constructor(
private _router: Router){}
logout() {
localStorage.removeItem("user");
this._router.navigate(['Login']);
}
login(user){
var authenticatedUser = users.find(u => u.email === user.email);
if (authenticatedUser){
localStorage.setItem("user", authenticatedUser);
this._router.navigate(['Home']);
return true;
}
return false;
}
checkCredentials(){
if (localStorage.getItem("user") === null){
this._router.navigate(['Login']);
}
}
}
錯誤
[在裝載機] SRC \應用\認證\認證的參數.service.ts:32:36 'User'類型的參數不能分配給'string'類型的參數。
絕對正確。爲什麼我不能專注於它 – Pravin
@Pravin碰巧對我們最好的:-) – echonax
感謝等待一分鐘來回答 – Pravin