Reputation: 3670
Let's say I have 3 components, namely A
, B
, and C
. Component A
has this in its HTML:
// a.component.html
<b-component></b-component>
<c-component></c-component>
Is there a way that component A
can send data to each of B
and C
and tell them to update from time to time?
BTW, the question is in Angular, not AngularJS.
Upvotes: 0
Views: 193
Reputation: 4754
Yes, you can do this as below. data_item
from component a will be sent to component b.
a.component.html
<b-component [data]="data_item"></b-component>
b.component.ts
@Input()
data: any
Simple demo here: https://stackblitz.com/edit/angular-data-to-component?file=src/app/app.component.html
Upvotes: 1
Reputation: 1479
Since the components are unrelated, sharing data via Service
is a good option.
Upvotes: 0
Reputation: 467
https://angular.io/guide/component-interaction this document is very useful.You set an @output from component A and set @input in component B and C . When the value of that varibale change emit an event from A which must handle in B and C
this is an example code https://stackblitz.com/edit/angular-component-interaction-4?file=app%2Fvoter%2Fvoter.component.ts
Upvotes: 0