Skip to content

Instantly share code, notes, and snippets.

@sokhomhuy
Last active June 14, 2018 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sokhomhuy/b4c46fa8dc573c516295735505ec3fcc to your computer and use it in GitHub Desktop.
Save sokhomhuy/b4c46fa8dc573c516295735505ec3fcc to your computer and use it in GitHub Desktop.
Custom ngInit in Angular 2+
import { Directive, Output, EventEmitter, Input, SimpleChange } from '@angular/core';
@Directive({
selector: '[ngInit]'
})
**export class NgInit {
@Output() ngInit: EventEmitter<any> = new EventEmitter<any>();
constructor() { }
ngOnInit() {
this.ngInit.emit();
}
}
**
@sokhomhuy
Copy link
Author

sokhomhuy commented Jun 14, 2018

  • to use this directive
    EX: <div (ngInit)="yourFunctionHere()">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment