0

I have 2 components. component A and component B. In component A has an output that when emit set an input in component B when this happens I get this error:

expression has been changed after it was checked.

The components are shown below:

<app-cmp-A (onSelect)="selectedData = $event"></app-cmp-A>
<app-cmp-B [selectedItem]="selectedData"></app-cmp-B>

My question is that why this error happen and this scenario is very useful when we use cascading component that one component require output another?

luiscla27
  • 4,956
  • 37
  • 49
  • https://blog.angularindepth.com/everything-you-need-to-know-about-the-expressionchangedafterithasbeencheckederror-error-e3fd9ce7dbb4 – Florian Jan 14 '19 at 09:16
  • 1
    Possible duplicate of [How to manage Angular2 "expression has changed after it was checked" exception when a component property depends on current datetime](https://stackoverflow.com/questions/39787038/how-to-manage-angular2-expression-has-changed-after-it-was-checked-exception-w) – Akber Iqbal Jan 14 '19 at 09:42

1 Answers1

0

This will not be effective if you are not loading both the components together! If you cannot still detect it with the above solution, you can use subject and pass the value inside the subject! So it can be subscribed in the other component and the data can be sent!