Я новичок в Angular 7. Я работаю в проекте Angular 7. У меня есть login
компонент, как показано ниже
import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { TokenService } from '../../token.service'
import { Router, ActivatedRoute } from '@angular/router';
import { ServerService } from 'src/app/server.service';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
response: any;
failmsg: boolean = false;
constructor(private http: HttpClient,
private server: ServerService,
private Token: TokenService,
private router: Router,
private _router: ActivatedRoute
) { }
public form = {
grant_type: 'password',
client_id: 2,
client_secret: 'W5nQYuW1OFknDwiDnU96Y7dBMqTJ5jG6r6AXYk9q',
username: null,
password: null
}
headers = new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + this.handleResponse2()
});
login() {
this.http.post(this.server.base_url + "login", this.form).subscribe( //execution is not entering inside this block
(data) => {
this.handleResponse(data);
this.http.get(this.server.base_url + "employees/employee/user/profile", { headers: this.headers }).subscribe(
(profile) => {
this.employeeProfile = profile;
if (this.employeeProfile.user_id == 1) {
this.router.navigate([this._router.snapshot.paramMap.get("portal") + '/home/dashboard'])
.then(rel => location.reload());
} else {
localStorage.setItem('employeeId', this.employeeProfile.employeeId);
localStorage.setItem('id', this.employeeProfile.id);
this.router.navigate([this._router.snapshot.paramMap.get("portal") + '/home/employee-dashboard'])
.then(rel => location.reload());
}
}
)
},
(error) => { //execution is entering inside this block
console.log('hello');
if (error) {
this.failmsg = true;
}
console.log(error);
}
);
}
employeeProfile: any;
handleResponse(data) {
this.Token.set(data.access_token);
this.headers = new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + this.handleResponse2()
});
}
onClose() {}
handleResponse2() {
return this.Token.get();
}
ngOnInit() {
localStorage.setItem('portal', this._router.snapshot.paramMap.get("portal"));
this.server.set_base_url(this._router.snapshot.paramMap.get("portal"));
this.server.set_base_url2(this._router.snapshot.paramMap.get("portal"));
}
}
Я не могу войти. Я получаю сообщение об ошибке, как показано ниже
![enter image description here](https://i.stack.imgur.com/3P6f8.png)
Моя сетевая вкладка похожа на
![enter image description here](https://i.stack.imgur.com/6HioK.png)
Может ли кто-нибудь помочь мне решить эту проблему?