Angular 4/ 5 data from one component to another
Ways of passing data from one component to another in angular 4 or 5
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ramesh PalanivelRank #372 · 6.8K reputationPosted May 24, 2018, 4:01 AM EDT
Bhairab DuttRank #799 · 2.9K reputationPosted May 24, 2018, 10:03 AM EDT
//Parent Component
import { Component } from '@angular/core'
@Component({
selector: 'parent-app',
template:
`
})
export class ParentComponent{
pdata: string = 'test';
}
//Child Component
import { Component, Input } from '@angular/core';
@Component({
selector: 'child-app',
template: `
{{ parentdata }}
`
})
export class ChildComponent {
@Input()
parentdata: string;
}
3- In case if you want to pass the data from one component to another component you can use service.
Thanks.
Debasis SahaRank #21 · 46.5K reputationPosted May 24, 2018, 5:13 AM EDT