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
(basepath/src/app/hello-world)
Below is how the code looks
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() {
}
}
@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.