1 ISSUE
I am trying to implement the following:
I have a container component ContainerComponentand child components ChildComponent. I want to change the rendering and general behavior of child components with ContainerComponent.
2 USED TECHNOLOGIES
Angular2, HTML, CSS, Javascript, Typescript,ES6
3 CODE
ContainerComponent.ts
export class ContainerComponent {
children: Array<Child>;
constructor(
private _el: ElementRef,
private _dcl: DynamicComponentLoader,
private _childService: ChildService) {
}
ngOnInit() {
let index = 0;
this._childService.getChildren().then(
(children) => {
this.children = children;
this.children.forEach((child, index) => {
this._dcl.loadIntoLocation(ChildComponent, this._el, 'dynamicChild')
.then(function(el){
el.instance.child = child;
el.instance.index = index;
});
});
}
);
}
}
ChildComponent.ts
export class ChildComponent {
child: Child;
index: number;
constructor(private _renderer: Renderer, private _el: ElementRef) {
}
ngOnInit() {
let delay = (this.index + 1) * 0.5; // calculate animation delay
this._renderer.setElementStyle(this._el, '-webkit-animation-delay', delay + !important');
this._renderer.setElementStyle(this._el, 'animation-delay', delay + !important');
}
}
4 EXPLANATION OF CODE
In the above code, ContainerComponentdynamically inserts ChildComponent(provided, this can be done without DynamicContentLoader).
ChildComponentsshould dynamically add css properties, in this case, the delay of the animation after it is displayed. Therefore, based on the index of the child, the delay in the animation increases.
, css .