[Fixed] How to access a Component.ts from another Component.ts (in the same app.component.html)

Issue

I have this code that creates 3 SectionComponent inside app.component.html.

 <div *ngFor="let section of sectionObjectList">
    <app-section [section]="section" ></app-section>
  </div>

Now, from a SectionComponent.ts (class) I need to access the other SectionComponent.ts (class), to minipulate the fields and call functions inside them.

How can I do it? What’s the correct way?

Thank you

Solution

Feom what you have written i can say that you can use @output in the section component and then that event can be captured in the app component and based upon that the values of array coupd be changes
And if you dont want to use @Output
The besy way will be link the functions to the service and that emit subject when changes are made which can be subscribed in the app component

Leave a Reply

(*) Required, Your email will not be published