我无法显示基于user_id的component.html和仪表板
我正在使用Angular连接到Laravel端点。我有用户模型和其他模型。其他所有表中都有user_id。有两个仪表板:admin-dashboard和user-dashboard。
Laravel
public function login()
{
$credentials = request(['email', 'password']);
if (!$token = auth()->attempt($credentials)) {
return response()->json(['error' => 'Email or Password doesn\'t exisit'], 401);
}
return $this->respondWithToken($token);
}
用户,学生和作业的模型:
protected $fillable = [
'name', 'email', 'password', 'username',
];
protected $fillable = [
'name', 'class', 'user_id',
];
protected $fillable = [
'title', 'valid_date', 'content', 'user_id',
];
角度:服务
private baseUrl = 'http://localhost/cloudengine-sandbox/cloudsandboxbackend/public/api';
//private baseUrl = '/api';
constructor(private http:HttpClient) { }
register(data){
return this.http.post(`${this.baseUrl}/register`, data)
}
login(data){
return this.http.post(`${this.baseUrl}/login`, data)
}
login.component.ts
onSubmit() {
this.Jarwis.login(this.form).subscribe(
data => this.handleResponse(data),
error => this.handleError(error)
);
}
handleResponse(data){
this.Token.handle(data.access_token);
this.Auth.changeAuthStatus(true);
//this.user.loggedInUser = user;
this.router.navigateByUrl('/admindashboard');
}
我登录时:
答案 0 :(得分:0)
只需在handleResponse方法中添加if检查,
tell(-1234567890) --> "minus "
tell(123456789)
tell(12345678)
tell(1234567)
tell(123456)
tell(12345)
tell(1234)
tell(123)
tell(12)
tell(1) ... recursion ends because 1 / 10 == 0
printf("%s ", digit[1 % 10]) --> "one "
printf("%s ", digit[12 % 10]) --> "two "
printf("%s ", digit[123 % 10]) --> "three "
printf("%s ", digit[1234 % 10]) --> "four "
printf("%s ", digit[12345 % 10]) --> "five "
printf("%s ", digit[123456 % 10]) --> "six "
printf("%s ", digit[1234567 % 10]) --> "seven "
printf("%s ", digit[12345678 % 10]) --> "eight "
printf("%s ", digit[123456789 % 10]) --> "nine "
printf("%s ", digit[1234567890 % 10]) --> "zero "
更好的方法是使用Using Route Guards。