I created two components and named it as parent and child. And I linked these components at app.component.html. Now I have an array of objects in child component, My goal is to show those array of objects in parent component by using @Output. My Expected output is Each object should be in a separate div.
If I am not clear with my doubt please put a comment.
This is app.component.html
<div class="container">
<div class="row">
<div class="col-6">
<app-parent></app-parent>
</div>
<div class="col-6">
<app-child></app-child>
</div>
</div>
</div>
This is app.component.css
There is no css in this
This is childcomponent.html
<div class="childclass">
<h1>This is Child</h1>
</div>
This is childcomponent.css
.childclass {
background-color: burlywood;
}
This is childcomponent.ts
import { Component, OnInit, EventEmitter, Output } from '@angular/core';
@Component({
selector: 'app-child',
templateUrl: './child.component.html',
styleUrls: ['./child.component.css']
})
export class ChildComponent implements OnInit {
employs = [
{
name: `Mark`,
age: 27,
jobProfile: 'React Developer'
},
{
name: 'Williams',
age: 29,
jobProfile: 'Angular Developer'
},
{
name: 'Tom',
age: 32,
jobProfile: 'Vuejs Developer'
}
]
@Output()
outputFromChild: EventEmitter<any> = new EventEmitter<any>()
constructor() { }
ngOnInit() {
}
}
This is parentcomponent.html
<div class='parentclass'>
<h1>This is Parent</h1>
</div>
This is parentcomponent.css
.parentclass {
background-color: aqua;
}
This parentcomponent.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-parent',
templateUrl: './parent.component.html',
styleUrls: ['./parent.component.css']
})
export class ParentComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}