简体   繁体   中英

Why value in child component is not changed after emit from parent?

I have a parent component view-event-component within child component inside:

<app-visitor-component (message)="message($event)" [_event]="event"></app-visitor-component>

Inside view-event-component there is:

  public dataFromChild: any;

  message($event) {
      console.log($event);
      this.dataFromChild = $event;
  }

Template view-event-component is:

{{ dataFromChild }}

So, when I push data from parent to child using @Output I always get message in:

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

If you have:

changeDetection: ChangeDetectionStrategy.OnPush

Trigger manually changeDetection:

constructor(cd: ChangeDetectorRef) {}

triggerDetecton():void {
    this.cd.detectChanges();
}

You also should provide a StackBlitz to help us understand better

try like this in child:

message= new EventEmitter<Object>();
messagefunction(event) {
    this.messageEvent.emit(event);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM