Skip to content

Instantly share code, notes, and snippets.

@gitawego
Last active September 23, 2018 09:35
Show Gist options
  • Select an option

  • Save gitawego/13b8703be4b068fc7c0a90124141a35a to your computer and use it in GitHub Desktop.

Select an option

Save gitawego/13b8703be4b068fc7c0a90124141a35a to your computer and use it in GitHub Desktop.
[Angular Tips] #tips

ngInit in angular 2/4

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment