[英]Why value in child component is not changed after emit from parent?
I have a parent component view-event-component
within child component inside:我在子组件内部有一个父组件
view-event-component
组件:
<app-visitor-component (message)="message($event)" [_event]="event"></app-visitor-component>
Inside view-event-component
there is:在
view-event-component
里面有:
public dataFromChild: any;
message($event) {
console.log($event);
this.dataFromChild = $event;
}
Template view-event-component
is:模板
view-event-component
是:
{{ dataFromChild }}
So, when I push data from parent to child using @Output
I always get message in:因此,当我使用
@Output
将数据从父级推送到子级时,我总是会收到消息:
message($event) {
console.log($event);
}
But variable is not showed (rendered) in template:但是变量没有在模板中显示(渲染):
{{ dataFromChild }}
There are no errors and warnings.没有错误和警告。
I use last version of Angular and Mozilla Firefox我使用最新版本的 Angular 和 Mozilla Firefox
If you have:如果你有:
changeDetection: ChangeDetectionStrategy.OnPush
Trigger manually changeDetection:手动触发changeDetection:
constructor(cd: ChangeDetectorRef) {}
triggerDetecton():void {
this.cd.detectChanges();
}
You also should provide a StackBlitz to help us understand better您还应该提供 StackBlitz 以帮助我们更好地理解
try like this in child:在孩子身上试试这样:
message= new EventEmitter<Object>();
messagefunction(event) {
this.messageEvent.emit(event);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.