Angular 5 Introduction

After a long hiatus from Angular, started building a website with Angular 5 recently and was pleasantly surprised by the complete overhaul of the framework compared to older versions that I was familiar with(Angular 2):

Getting Started:

npm install -g @angular/cli
ng new <project-name>
npm start

Voila! Your Angular app is up and running.

Now let’s do something useful aka build a component(e.g: a login component):

ng g c login

This will generate a login component with the following files:

The structure is similar to earlier versions of Angular which used Javascript instead of Typescript.

To use this component, it has to be exported as an app module in app.module.ts:

import { LoginComponent } from './login/login.component';
@NgModule({
  declarations: [
    LoginComponent
	]})

Provide routing for the same in app.routing.module.ts:

import { LoginComponent } from './login/login.component';
const routes: Routes = [
 { path: '',
    redirectTo: '/login',
    pathMatch: 'full'
  },
  { path: 'login', component: LoginComponent }
 ];

Now to serve it on the app default webpage, edit app.component.html to contain:

<router-outlet></router-outlet>

That’s it. Easy as that. Now you can build slick interfaces using Angular and Angular Material. I will write more on this in subsequent posts.