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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ramesh PalanivelPosted May 24, 2018, 8:01 AM
Bhairab DuttPosted May 24, 2018, 2:03 PM
//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 SahaPosted May 24, 2018, 9:13 AM