Implement this interface to execute custom initialization logic after your directive's data-bound properties have been initialized.

ngOnInit is called right after the directive's data-bound properties have been checked for the first time, and before any of its children have been checked. It is invoked only once when the directive is instantiated.

Examples

Try this live example from the Lifecycle Hooks page:

// Spy on any element to which it is applied. // Usage: <div mySpy>...</div> @Directive(selector: '[mySpy]') class SpyDirective implements OnInit, OnDestroy { final LoggerService _logger; SpyDirective(this._logger); ngOnInit() => _logIt('onInit'); ngOnDestroy() => _logIt('onDestroy'); _logIt(String msg) => _logger.log('Spy #${_nextId++} $msg'); }

Constructors

OnInit()

Properties

hashCode → int

Get a hash code for this object.

read-only, inherited
runtimeType → Type

A representation of the runtime type of the object.

read-only, inherited

Operators

operator ==(other) → bool

The equality operator.

inherited

Methods

ngOnInit() → dynamic

noSuchMethod(Invocation invocation) → dynamic

Invoked when a non-existent method or property is accessed.

inherited
toString() → String

Returns a string representation of this object.

inherited