I'm not sure what to do, The code for the app.component
import { Component} from '@angular/core';
import { AuthService } from './login/auth.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
authNavShow: boolean = false;
constructor(private authService: AuthService){
}
ngOnInit(){
this.authService.authNav.subscribe(
mostrar => this.authNavShow = mostrar,
);
console.log(this.authService.userData);
if(this.authNavShow != true){
var auth: boolean = true;
}
}
}
the auth.service code
import { Injectable,EventEmitter } from '@angular/core';
import { Router } from '@angular/router';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class AuthService {
constructor(private http: Http, private router: Router) { }
private userAuth: boolean = false;
authNav = new EventEmitter<boolean>();
userData = new EventEmitter();
fazerLogin(dataLogin){
this.http.post('http://localhost:88/login',
JSON.stringify(dataLogin))
.map(dados => dados.json())
.subscribe(dados => this.checkLogin(dados)
);
}
checkLogin(dados){
if(dados.success == true){
this.userAuth = true ;
this.authNav.emit(true);
this.userData.emit(dados);
this.router.navigate(['/']);
}
}
userAuthenticated(){
return this.userAuth;
}
}
What I need is to pull the object data in my app.component but I do not know any way or way, if anyone can help me thank you very much!