0

what does it mean "called after data-bound properties of a directive are initialized" in ngOnInit definition?

  • 2
    take a look `http://stackoverflow.com/questions/39367423/what-is-ata-bound-properties` – Sameer K May 12 '17 at 03:47
  • Possible duplicate of [What is ata-bound properties?](http://stackoverflow.com/questions/39367423/what-is-ata-bound-properties) – JayChase May 12 '17 at 04:50

1 Answers1

0

ngOnInit is a life cycle hook called by Angular 2 to indicate that Angular is done creating the component.

We need to import OnInit in order to use like this (actually implementing OnInit is not mandatory but considered good practice):

import {Component, OnInit} from '@angular/core';

then to use the method of OnInit we have to implement in the class like this.

export class ClassName implements OnInit{
  constructor(){
     //called first time before the ngOnInit()
  }

  ngOnInit(){
     //called after the constructor and called  after the first ngOnChanges() 
  }
}

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.

Please check this Link