Say we have this component:
@Component({
template: `
<div *ngFor="let v of values;" #aService="getServiceInstance()">
<child-component1 [s]="aService"></child-component1>
<child-component2 [s]="aService"></child-component2>
</div>
`
})
export class MyComponent {
values = [1,2,3,4,5];
getServiceInstance(){
// ??? how to implement this ???
}
}
my question is - how can I implement the getServiceInstance() method so that I inject a new service instance into the child-component? Is there a way to do that somehow? Maybe using a decorator?
I am guessing that something like this is possible:
@Inject(MyService)
getServiceInstance(ms: MyService){
ms.13 = 'dangerous';
return ms;
}
but that's just a guess.
*ngForloop in the template should you want to pass the service to the child component.