Sunday, 9 February 2020

how to create login page in angular 9 with Example?





In this Angular 9 article, we’ll study to create attractive login and registration UI template with Angular Material 8. We’ll need the help of Material design components and Angular 8 flex design CDK to build the login and registration template. We’ll build an easy Angular 9 application from scratch and execute a login and registration UI module in it. You can review out below, how we’ll save a simple login and registration HTML form into a nice UI template.


Table of contents


  1.  Prerequisite
  2. Setup Angular project
  3.  Create components using Angular CLI
  4. Executing Angular Material 8
  5.  Design Custom Angular Material Module
  6. Initialize Routing
  7. Build Angular Material Navbar
  8. Design Registration UI with Material Design

1). Prerequisite

Firstly, we’ll install and configure an Angular project of new. I understand you’ve already installed Node.js and Angular CLI in your system.
I did following command to install Angular CLI:

npm install @angular/cli -g

2). Setup Angular Project

Enter command in terminal and connected enter to build a new Angular project.
ng new angular-material-login-template

# ? Would you like to add Angular routing? = Yes
# ? Which stylesheet format would you like to use? = CSS

Get into the project folder:


    cd angular-material-login-template

3). Create Components Using Angular CLI

Components are a reusable part of code in an Angular application. You can build components immediately applying a single command. Run the command to generate login and registration components in an Angular project.

             ng g component components/log-in --module app
             ng g component components/register --module app

4). Executing Angular Material 8
Run the next command to install Angular Material 8 UI library in Angular project:
 ng add @angular/material


5). Design Custom Angular Material Module


It is always the most reliable method to build a separate module files to import Angular Material components. It provides your code to look extra appealing, Go to src > app folder and generate angular-material.module.ts file and add the following code:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
 
import {
   MatButtonModule,
   MatToolbarModule,
   MatIconModule,
   MatBadgeModule,
   MatSidenavModule,
   MatListModule,
   MatGridListModule,
   MatFormFieldModule,
   MatInputModule,
   MatSelectModule,
   MatRadioModule,
   MatDatepickerModule,
   MatNativeDateModule,
   MatChipsModule,
   MatTooltipModule,
   MatTableModule,
   MatPaginatorModule
} from '@angular/material';
 
@NgModule({
   imports: [
      CommonModule,
      MatButtonModule,
      MatToolbarModule,
      MatIconModule,
      MatSidenavModule,
      MatBadgeModule,
      MatListModule,
      MatGridListModule,
      MatFormFieldModule,
      MatInputModule,
      MatSelectModule,
      MatRadioModule,
      MatDatepickerModule,
      MatNativeDateModule,
      MatChipsModule,
      MatTooltipModule,
      MatTableModule,
      MatPaginatorModule
   ],
   exports: [
      MatButtonModule,
      MatToolbarModule,
      MatIconModule,
      MatSidenavModule,
      MatBadgeModule,
      MatListModule,
      MatGridListModule,
      MatInputModule,
      MatFormFieldModule,
      MatSelectModule,
      MatRadioModule,
      MatDatepickerModule,
      MatChipsModule,
      MatTooltipModule,
      MatTableModule,
      MatPaginatorModule
   ],
   providers: [
      MatDatepickerModule,
   ]
}) export class AngularMaterialModule { }
import it to app.module.ts:

/* Angular material */
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AngularMaterialModule } from './angular-material.module';
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
 
@NgModule({
  declarations: [...],
  imports: [
    BrowserAnimationsModule,
    AngularMaterialModule,
  ],
  providers: [...],
  bootstrap: [...],
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class AppModule { }

6). Initialize Routing

In this step, we’ll initialize routing in our material design authentication UI template. Routing enables users to go from one part to different components. To activate routing in Angular app, we’ll explain the routing configuration in app-routing.module.ts.

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { LogInComponent } from './components/log-in/log-in.component';
import { RegisterComponent } from './components/register/register.component';
 
const routes: Routes = [
  { path: '', pathMatch: 'full', redirectTo: 'login' },
  { path: 'login', component: LogInComponent },
  { path: 'register', component: RegisterComponent }
];
 
@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

7). Create Angular Material Navbar

 
Now, we are building a navbar applying the Angular Material UI library. First, include <router-outlet></router-outlet> directive in app.component.ts. It displays the routed component on the front-end:
 
<!-- Toolbar -->
<mat-toolbar color="primary" class="app-header">
  <div><a href="https://www.positronx.io" target="_blank" class="positronx">PositronX.io</a></div>
  <span class="nav-tool-items">
    <a mat-button routerLink="login" routerLinkActive="active">Log in</a>
    <a mat-button mat-raised-button routerLink="register" routerLinkActive="active">Register</a>
  </span>
</mat-toolbar>
<router-outlet></router-outlet>
 

Saturday, 8 February 2020

Improved CSS class and style binding in Angular 9



The Ivy compiler and runtime implements improvements for handling styles. Previously, if an application received competing explanations for a style, those styles would destructively follow various other. With Ivy, the styles are united in a likely way.
<my-component style="color:red;" [style.color]="myColor" [style]="{color: myOtherColor}" myDirective></div>

@Component({
host: {
style: "color:blue"
},...
})
...
@Directive({
host: {
style: "color:black",
"[style.color]": "property"
},...
})



Previously, whichever binding was estimated end would get, and this could depend on the timing of moves to these conclusions. If myColor and myOtherColor both did undefined, the static ‘red’ style would be overlooked.
With version 9, you can control your styles into a clear, logical sequence of priority that isn’t subject to timing. The various special styles constantly have the highest precedence. For example, a binding to [style.color] cancels a different binding to [style].
However, for backward agreement ends, we have left [ngStyle] and [ngClass] covers the way the same as before. When their required values are updated, the current values will reverse any competing bindings.
You can see more about styling priority customs in the Template Syntax guide in the documentation.
As a facet impact of the styling refactoring, you can now also connect to CSS custom properties (also known as CSS variables).

What is New in Angular 9 and how to update old version ?



Angular 9 was published on February 7, 2020. Version 9 passes all applications to do the Ivy compiler and runtime by default. Angular has been updated to run with TypeScript 3.6 and 3.7. In increase to 100 of bug fixes, the Ivy compiler and runtime allows many advantages:

The 9.0.0 release of Angular is here! That is a larger release that crosses the whole platform, including the framework, Angular Material, and the CLI. The release shifts applications to the Ivy compiler and runtime by default and offers enhanced ways of testing components.

That is one of the largest updates to Angular we have done in the earlier 3 years and we are charged for all of the ways it allows developers to build more reliable applications and provide to the Angular ecosystem

How to update to version 9
Proceed to this website update.angular.io for complete knowledge and guidance. To have the biggest update practice, we suggest your initial update to the last release of Angular 8.
First, update to the newest version of 8
ng update @angular/cli@8 @angular/core@8
Now, update to 9
ng update @angular/cli @angular/core
Ivy

Version 9 runs all applications to do the Ivy compiler and runtime by default. In increasing to hundreds of bug fixes, the Ivy compiler and runtime allows many advantages:
·         Smaller bundle sizes
·         Faster testing
·         Great debugging
·         Updated CSS class and style coupling
·         Fixed type checking
·         Fixed build errors
·         Fixed build times, allowing AOT on by default
·         Bettered Internationalization

Smaller bundle sizes
The Ivy compiler has done created to extract parts of Angular that aren’t doing done via tree-shaking and to make less code for every Angular component.
With those changes, little apps, and large apps can see the most exciting size savings.
·         Little apps that don’t accept various Angular features that can help most from tree-shaking.
·         Big apps with several components can help most from the controlled facility size.
·         Medium-sized apps should observe bundle sizes that are on par or slightly less considering all benefit less from tree-shaking and don’t have sufficient components to truly leverage fewer factories.


Faster testing
We have also revised the implementation of TestBed in Ivy to make it extra useful.
Before, TestBed would recompile all components in the running of each test, although of whether there were any modifications done to components (for example, through overrides).
In Ivy, TestBed doesn’t recompile parts in tests except a component has been manually revoked, which enables it to withdraw recompilation between the grand majority of tests.
With this update, the framework’s core taking tests are about 40% faster. We would require users to see their own application test speeds to be around 40–50% faster.

Better debugging
Ivy gives you larger tools to debug your applications. When running an application in Dev Mode with the Ivy runtime, we now offer the new  ng object for debugging.
·         You can ask Angular for a way to occurrences of your components, directives, and more
·         Manually call methods and update the state
·         When you require to see the results of change disclosure, you can trigger change detection with applyChanges

Ivy also increases the total trace for debugging problems such as the ExpressionChangedAfterItHasBeenCheckedError. Before the stack trace could be unhelpful:

By Ivy, you view an extra helpful stack trace that enables you to jump straight to the template instruction with the appearance that has changed.

Improved CSS class and style binding
The Ivy compiler and runtime executes changes for handling styles. Previously, if an application accepted fencing solutions for a style, those styles would destructively succeed each other. With Ivy, the styles are mixed in an expected way.

Improved type checking
The Angular the compiler can examine more of the types of your application, and it can apply extra strict rules. These articles will help you and your team find bugs beginning in the development process.
Improved build errors
The new Ivy the compiler is not only faster and allows the more effective type of safety, but it also offers each of the error messages easier to read.

Improved build times, enabling Ahead-of-Time compiler by default

Thanks to Ivy’s new construction, we’ve made important changes to the compiler’s execution.
We hold our compiler’s achievement in terms of the overhead on top of a plain TypeScript collection of an application. For our documentation app (angular.io), this overhead subtracted from 0.8x to 0.5x with Ivy, an increase of approximately 40%.

Improved internationalization (i18n)
Internationalization must be a core feature of Angular, where you could develop your application once per locale and take really optimized and limited applications. In 9.0, we’re executing this active by leading the build-time i18n changes following in the build method. This variation allowed us to get it up to 10 times faster.