Ich habe eine Variable namens LoginResponse, die die Antwort speichert, die ich vom Server nach der Anmeldung erhalte. Ich leite die App bei erfolgreicher Anmeldung in das Dashboard um. Ich wünsche Login für den Zugriff auf in meinem Dashboard.component.tsDer Zugriff auf die übergeordnete Komponente ist nicht möglich. Untergeordnete Komponente - Angular 4
LOGIN FUNKTION IN 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);
}
);
}
DASHBOARD 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(['/']);
// }
}
Wie funktioniert Ihre Dashboard-Komponente in HTML-Datei auf Eltern? – Sajeetharan
Screenshot in OP hinzugefügt. @Sajeetharan –
nicht das Verzeichnis, wie Sie den Wert in HTML übergeben haben. Fügen Sie den Code der übergeordneten Komponente ein – Sajeetharan