Wednesday 2 January 2019

Introduction to Angular6: A beginner’s guide - Part 2

Introduction to Angular6: A beginner’s guide  - Part 1

How to Create a Component


Use ng generate to create a new component
 
 
 
iTechnoFreaks
> ng generate component hello-world


Let's look into our component class HelloWorldComponent

(basepath/src/app/hello-world)

Below is how the code looks


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

@Component({
selector: 'app-hello-world',
templateUrl: './hello-world.component.html',
styleUrls: ['./hello-world.component.scss']
})
export class HelloWorldComponent implements OnInit {

constructor() { }

ngOnInit() {
}

}
Each component has a lifecycle of create, update and destroy. angular exposes hooks to interfare when these events occur in a component’s lifetime. these hooks can be implemented using corresponding lifecycle hook interface from angular core library.