print EventEmitter data in angular 2

1

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!

    
asked by anonymous 21.06.2017 / 15:46

1 answer

1

No ngOnInit of your app.component.ts you will have to do the same as this.authService.authNav

  ngOnInit(){
        this.authService.userData.subscribe(data => this.userData = data);
        this.authService.authNav.subscribe(mostrar => this.authNavShow = mostrar);
  }

Then you will have to start a pointer like this.authNavShow , only with the name of userData

    
21.06.2017 / 16:23