は私が...機能が完了するまでに角度2 * ngが表示されないのはなぜですか?
// Pug Template
.notification-header-area.layout-row.layout-align-center-center(*ngIf="notification.message != null", class="{{notification.color}}")
// Inside angular component
private onNotificationStart = (notification) => {
this.notification = notification;
console.log(this.myElement.nativeElement);
if (this.myElement.nativeElement.children.length > 0) {
// TODO: We should probably do this in a more reliable way in case the template changes.
let elm = this.myElement.nativeElement.children[0];
if (notification.fontSize) elm.style.fontSize = notification.fontSize;
if (notification.colorBackground) elm.style.backgroundColor = notification.colorBackground;
if (notification.colorFont) elm.style.color = notification.colorFont;
}
}
を次のコードを持っている問題は、私は、コンソールラインでデバッグする場合は、ブラウザが通知DOM要素を示していないです。 console.logステートメントには、オブジェクトを書き出すときにもそのステートメントがありません。関数が実行を完了すると、ngIfがレンダリングされ、要素が期待どおりに表示されます。 $タイムアウトに相当するものがありますか?私はこのイベントをWebソケットから取得しており、Trouble with *ngIf in Angular 2 (TypeScript)を試しましたが、動作しませんでした。私はまた、私のシンプルなプランナー(Webソケットを使用していない)で再作成できなかったので、私はまだデモを探しています。
また、私は...それは動作します。このようなタイムアウトで折り返す場合
private onNotificationStart = (notification) => {
this.notification = notification;
setTimeout(() => {
console.log(this.myElement.nativeElement);
if (this.myElement.nativeElement.children.length > 0) {
// TODO: We should probably do this in a more reliable way in case the template changes.
let elm = this.myElement.nativeElement.children[0];
if (notification.fontSize) elm.style.fontSize = notification.fontSize;
if (notification.colorBackground) elm.style.backgroundColor = notification.colorBackground;
if (notification.colorFont) elm.style.color = notification.colorFont;
}
})
// if(notification){
// this.myElement.nativeElement.style.backgroundColor =
// }
}
私は質問や問題が何かを得ることはありません。期待される行動は何ですか? –
なぜ "* ng機能が完了するまでレンダリングしない"という問題がありますか? –
これには同じ問題はありませんhttps://plnkr.co/edit/E2o56qn4el7cniofwvZK?p=previewだから私のことは何ですか? – Jackie