user1603128
user1603128

Reputation: 21

angular 2 meteor InjectUser

I work with angular 2 meteor. I can not to get user in constructor:

export class Page extends MeteorComponent {
currentUser:Meteor.User;
constructor() {
    super();

    console.log(this.currentUser);
    //undefined
}

click(){
    console.log(Meteor.user());
    //Object{...}
}

Upvotes: 2

Views: 356

Answers (1)

dttung1412
dttung1412

Reputation: 93

Is this what you need ?

import { InjectUser } from 'angular2-meteor-accounts-ui';
...
@InjectUser('currentUser')
export class Page extends MeteorComponent{
  currentUser: Meteor.User;
}

Edit: A bit more explanation In the above code, you have just declared currentUser type not actually assign it to anything yet, so the undefined result is obvious.

Upvotes: 1

Related Questions