see on stackoverflow
create your own directive
import { Directive, Input } from '@angular/core';
@Directive({
selector: '[ngInit]'
})
export class NgInit {
@Input() ngInit;
ngOnInit() {
if (this.ngInit) {
this.ngInit();
}
}
}and then use it like
<div *ngIf="ramadan.date === date && ramadan.time === clock">
<div *ngIf="ramadan.checked" [ngInit]="play"></div>
<div *ngIf="!ramadan.checked" [ngInit]="pause"></div>
</div>