我有一個名爲LoginResponse的變量,它存儲我登錄後從服務器獲得的響應。我成功登錄後將應用重定向到儀表板。 我希望在我的Dashboard.component.ts訪問LoginResponse無法訪問子組件中的父組件變量 - 角4
登錄功能在APP COMP-
onLogin(form: NgForm) {
console.log(form);
this.serverService.Login(JSON.stringify(form.value))
.subscribe(
(response) => {
form.reset();
this.LoginResponse = response.json().data;
jQuery(this.modalcloser.nativeElement).modal('hide');
this.router.navigate(['/dashboard']);
console.log(this.LoginResponse);
},
(error) => {console.log(error.json()),
jQuery(this.modalcloser.nativeElement).modal('hide');
jQuery(this.errormodal.nativeElement).modal('show');
this.errormsg = (error.json().error);
}
);
}
儀表板COMP-
import { Component, OnInit, Input } from '@angular/core';
import { Router } from '@angular/router';
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.css']
})
export class DashboardComponent implements OnInit {
constructor(private router: Router) { }
@Input() LoginResponse: {token: string, teamname: string, member1name: string, member2name: string, member3name: string };
ngOnInit() {
console.log(this.LoginResponse);
}
// logOut() {
// this.router.navigate(['/']);
// }
}
如何做在父HTML儀表板組件? – Sajeetharan
在OP中添加了屏幕截圖。 @Sajeetharan –
不是目錄,你如何在html中傳遞值。粘貼父組件的代碼 – Sajeetharan