This article represents instructions and concepts related to How to create a Progressive Web Angular App (PWA) with Angular Material. Angular Material represents material design components for Angular apps.
The following page represents instructions and related concepts on creating PWAs using different Angular versions such as Angular 4 and Angular 5:
Angular PWA can be created with both, Bootstrap as well as Angular Material. From some of the following pages, it looks like Angular Material is preferred choice if you are looking for a WOW UI/UX experience.
Great news is Angular Material and Angular CDK has finally seen GA release (5.0.0).
Angular Material can now be considered stable set of libraries for enterprise-wide adoption. It would have a regular release cycle as like Angular. So, it can be considered safe enough to adopt Angular Material in your next Angular app project.
Follow the instructions on this page, Angular Material – Getting Started to install the Angular Material and Angular CDK.
Go to the angular app project folder and execute the commands listed in above mentioned page.
The following represents the sample screenshot, we will try and achieve:
The following files need to be changed in order to achieve above:
To achieve above, the file app.component.ts would be changed appropriately as shown in the following code. A simplistic component with an array consisting of details which will be displayed in each of the card.
import { Component } from '@angular/core'; import {MatCardModule} from '@angular/material/card'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'app'; tiles = [ {title: 'Manholes in Kukatpally, Hyderabad', image: 'http://www.thehansindia.com/assets/1378_Manhole.jpg', descr: 'This is a man hole which can prove dangerous for kids playing around as well as bike riders.', user: 'Ajitesh Shukla', css: 'example-header-image', dislikes: 20}, {title: 'Traffic Jams in Bangalore', image: 'http://www.fakingnews.firstpost.com/wp-content/uploads/2016/06/Bangalore-traffic.jpg', descr: 'When will these traffic jams in Bangalore end???', user: 'Aiyana Shukla', css: 'example-header-image-2', dislikes: 40}, {title: 'Aadhar Card Linkage Sucks', image: 'http://www.aadhaarcardnumber.in/wp-content/uploads/2015/09/Link-aadhar-card-to-bank-account-online.jpg', descr: 'Aadhar card linkage with banks looks fake to me. How about you?', user: 'Arijit', css: 'example-header-image-3', dislikes: 25} ]; }
The corresponding app.component.html file would need to include selectors appropriate for displaying the cards. Make a note of some of the following in the code given below:
This is how the html file looked like:
<mat-grid-list cols="4" rowHeight="500px" gutterSize="8px"> <mat-grid-tile *ngFor="let tile of tiles"> <mat-card class="example-card"> <mat-card-header> <div mat-card-avatar class="{{tile.css}}"></div> <mat-card-title>{{tile.title}}</mat-card-title> <mat-card-subtitle>{{tile.user}}</mat-card-subtitle> </mat-card-header> <img mat-card-image src="{{tile.image}}" height="180"> <mat-card-content> {{tile.descr}} </mat-card-content> <mat-card-actions> <button mat-button>Dislike ({{tile.dislikes}})</button> <button mat-button>Share</button> </mat-card-actions> </mat-card> </mat-grid-tile> </mat-grid-list>
Angular material supports multiple components representing different UI elements. The following can be two different techniques to work with Angular Material components:
Note some of the following:
import { NgModule } from '@angular/core'; import {MatCardModule} from '@angular/material/card'; import {MatButtonModule, MatGridListModule} from '@angular/material'; @NgModule({ imports: [MatCardModule, MatButtonModule, MatGridListModule], exports: [MatCardModule, MatButtonModule, MatGridListModule], }) export class AppCustomMaterialModule { }
Note the changes such as following:
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { ServiceWorkerModule } from '@angular/service-worker'; import { AppComponent } from './app.component'; import { environment } from '../environments/environment'; import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; import {AppCustomMaterialModule} from './app-custom-material.module'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production }), BrowserAnimationsModule, AppCustomMaterialModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
You could create an Angular PWA with either Bootstrap or Angular Material. However, I am inclined to use Angular Material for my next app as this has gone full GA.
In recent years, artificial intelligence (AI) has evolved to include more sophisticated and capable agents,…
Adaptive learning helps in tailoring learning experiences to fit the unique needs of each student.…
With the increasing demand for more powerful machine learning (ML) systems that can handle diverse…
Anxiety is a common mental health condition that affects millions of people around the world.…
In machine learning, confounder features or variables can significantly affect the accuracy and validity of…
Last updated: 26 Sept, 2024 Credit card fraud detection is a major concern for credit…