0

次のように単純なコンポーネントをセットアップしました。

import { Component, OnInit } from '@angular/core';   
import { Meteor } from 'meteor/meteor'; 
import { InjectUser } from 'angular2-meteor-accounts-ui';

@Component({
    selector: 'my-component',
    template: 'Hello, World!'
})
@InjectUser('user')
export class myComponent implements OnInit {
    user: Meteor.User;

    ngOnInit() {
        console.log(this.user); // undefined
    }
}

this.userログインしたユーザーの情報が含まれていると思います。ロードされた後続のすべてのコンポーネントで機能しますが、ロードされた最初のコンポーネントthis.userundefined

コンポーネントが初期化される前に、ユーザーデータが事前に入力されるようにしたいと思います。そうすれば、すべてのコンポーネントで同じサブスクリプション コードを使用する必要がなくなります。どうすればいいですか?

4

1 に答える 1

1

主にhtmlレンダリングに使用されていると思います。タイプスクリプトコードでは、変数に割り当てるか、直接使用する必要@InjectUser('user')があります。this.user から取得するすべてのものは、 Meteor.user() からも取得しますthis.userMeteor.user()Meteor.userId()

于 2016-12-12T15:45:44.553 に答える