Statistics
The Highest Post







Statistics
Count 94
Avg 21.00
Min 21
Max 21
Angualr Top questions

Details



Peter Agyekum How does one share data between components in Angular? Parent to child using @Input decorator. @Component({ selector: 'app-parent', template: ` app-child [data]=data /app-child ` , styleUrls: ['./parent.component.css'] }) export class ParentComponent{ data:string = "Message from parent"; constructor() { } } @ViewChild decorator is used to reference the child component as “child” property. Using the ngAfterViewInit hook, we assign the child’s data property to the messageFromChild property and use it in the parent component’s template. Child to parent using @Output and EventEmitter In this method, we bind a DOM element inside the child component, to an event ( click event for example ) and using this event we emit data that will captured by the parent component:
Related Topics