로그인 한 후 authservice가 호출 된 다음 라우팅이 profilecomponent에 적용됩니다.angular 5 post request returns 두 번 반환
그러나 게시 요청이 두 번 전송되는 중이므로 Cors를 사용하지 않아서 미리 요청 된 요청이 될 수 없다고 가정합니다. Profile.component.ts ngoninit가 두 번 실행되는 것 같습니다. 정확한 id 뒤에 정의되지 않은 coinId가 오는 coinId가 먼저 수신됩니다.
5a273e34f5c5643e18c035dacoinId from profile2!
main.f2eaf663cdbf963d2af8.bundle.js:1 undefinedcoinId from profile2!
저는이 모든 것에 매우 익숙합니다.이 문제를 해결할 수 있는지 확실하지는 않지만, nginx 서버를 시작하려고합니다.
login.component.ts
let url = 'http://localhost:3000/api/login';
this.newService.login(url, user, user.username).subscribe(result => {
var value = result["user"];
var coinId = result.user.coinid;
this.router.navigate(['/profile', coinId]);
auth.service.ts
login(url: string, user: any, username: any)
{return this.http.post(url , user)
.do (res => this.setSession(res))
}
private setSession(authResult) {
const expiresAt = moment().add(authResult.expiresIn,'second');
this.loggedIn.next(!!localStorage.getItem('id_token'));
console.log(authResult.token + "dit is de token");
localStorage.setItem('id_token', authResult.idToken);
localStorage.setItem("expires_at", JSON.stringify(expiresAt.valueOf()));
}
profile.component.ts
ngOnInit() {
var coinId = this.route.snapshot.params['id'];
console.log(coinId + "coinId from profile2!")
this.router.navigate([ '/profile', {outlets: { formOutlet:
['profileform', coinAId]}}]);
}