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
> ng generate component hello-world

Let's look into our component class HelloWorldComponent


Below is how the code looks

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

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.