Cant show name of logged-in user - angular2

I just want to show the name of the current logged in user, but I cant make it works.
I wrote this on the app.component

import { Component } from '@angular/core';
import template from './app.component.html';
import {ROUTER_DIRECTIVES} from '@angular/router';
import {LoginButtons} from 'angular2-meteor-accounts-ui';
//import our Carousel Component
import {CSSCarouselComponent} from './imports/componenets/carousel/carousel.component';
import { InjectUser } from 'angular2-meteor-accounts-ui';

@Component({
    selector: 'app',
    template,
    directives: [ROUTER_DIRECTIVES, LoginButtons,CSSCarouselComponent]
})
@InjectUser('user')
export class AppComponent {
    user: Meteor.User;
    constructor() {

        console.log(this.user);
    }
    loginFacebook(event) {
        Meteor.loginWithFacebook({}, function(err){
            if (err) {
                throw new Meteor.Error("Facebook login failed");
            }
            console.log(Meteor.user().profile.name;);
        });
    }

console.log(this.user); underfined
console.log(Meteor.user().profile.name;); works and gives me the name, but I have no success to export it to the html and show that.

I had the same issue.

  1. It is non-reactive
  2. Needs to be loaded in a ReactiveVar

profileURL: ReactiveVar = new ReactiveVar(’’);

constructor() {
super();
this.autorun(() => {
this.ngZone.run(() => {
this.profileURL.get();
console.log(this.profileURL.get());
});
});

}

  1. Thusly by a subscribe,

this.subscribe(‘myProfile’, Meteor.userId, () => {
this.profileURL.set(Meteor.users.findOne());
}, true);

  1. Make sure you are using MeteorComponent.
1 Like