I am new in angular 6.
I am using ngComponentOutlet
in a for loop
I want to know how can I pass the data to my child component
My HTML
<div *ngFor="let item of items">
<ng-container *ngComponentOutlet="currentComponent"></ng-container>
</div>
My parent component who decides which component to chose
export class MyParentComponent implements OnInit {
constructor(private route: ActivatedRoute, private commonService: CommonService) { }
dynamicComponents = {
'firstchild': {
'1': FirstchildComponent
}
};
currentComponent: any;
items: any;
ngOnInit() {
// To get data from resolver
const routeResult = this.route.snapshot.data.data.result;
this.items = routeResult.items;
// select child component at basis of route
const routeParams = this.route.snapshot.params;
this.currentComponent = this.dynamicComponents[routeParams.pageName][routeParams.templateType];
}
}
My child component
export class FirstchildComponent implements OnInit {
@Input() magazineData: any[];
constructor() { }
ngOnInit() {
}
}
So I want to pass item (single item of loop) to FirstchildComponent
as a input
How can I do it?
I have checked with Injector
But as I am new, I don't really understand how injector works