0
私のイベントエミッタをpromiseのthenメソッド内で正しく機能させることができません。私は何の誤りもありません。それは単に、子コンポーネントにイベントエミッタをAngular 2の約束内で呼び出す
を呼び出すことはありません:これは、親コンポーネントのある
<tas-loginform
(isLoggingIn)="setLoginLoading($event)"
*ngIf="!isSigningUp">
</tas-loginform>
:
@Output() isLoggingIn = new EventEmitter<boolean>();
onLogin() {
this.isLoggingIn.emit(true); //<-- this gets called, so it works.
this.authService.loginUser(this.loginForm.value)
.then(() => {
console.log(this.isLoggingIn.emit); //<-- This logs out the method.
this.isLoggingIn.emit(false); //<-- This doesn't get called!
})
.catch((err) => console.log(err));
}
これは、親コンポーネントのHTMLテンプレート、header.component.htmlですタイプコード、header.component.ts:
setLoginLoading(bool: boolean) {
console.log(bool);
this.loginLoading = bool;
}
これは、イベントエミッタがpromiを呼び出すのとほぼ同じですその後、setLoginLoadingのconsole.logが実行されないため、コールバックが呼び出されることはありません。また、エラーメッセージがまったくないので、さらに難しくなります。
'.then()'ハンドラの中の 'this'があなたが望むオブジェクトを参照していると確信していますか?私がJSで働いていた前回のことは難しい問題であることを覚えています。 – Douglas
私は確信しています。私は、問題を再現しようとしているplunkrを作った。しかしplunkrは実際には動作しますが、私のコードでは動作しません。私は何か他のことが起こっているかもしれないと思います... http://embed.plnkr.co/l50UlTSAh3p102lG5Db9/ – TheMarlow
おそらく、あなたはゾーンとポリフィルをロードしますか? –