Getting Started on Angular 7

  •        0

We aggregate and tag open source projects. We have collections of more than one million projects. Check out the projects section.

Angular is a platform for building responsive web, native desktop and native mobile applications. Angular client applications are built using HTML, CSS and Typescript. Typescript is a typed superset of Javascript that compiles to plain Javascript. Angular core and optional modules are built using Typescript. Code has been licensed as MIT License.

In this article, we will guide you through to install Angular 7 and we will build web applications to display the products which will have functionality to edit, delete, create and search operation on the catalog. While creating the angular applications, will provide the details about the fundamentals.

Prerequisites for Installation

Angular requires NodeJS version, it is a Javascript runtime build environment. It can be downloaded from the NodeJS website, based on your OS download and install respective binary. It also requires npm, node package manager(npm) to download the packages and its dependency libraries.

hostname:~$ node -v

hostname:~$ npm -v


First install angular CLI interface with following command

  npm install -g @angular/cli

Verify the angular CLI command installed as below

 nagappan@nagappan-Latitude-E5450:~/AngularProjects$ ng version

 Angular CLI: 7.3.9
 Node: 10.16.0
 OS: linux x64

 Package Version
 @angular-devkit/architect 0.13.9
 @angular-devkit/core 7.3.9
 @angular-devkit/schematics 7.3.9
 @schematics/angular 7.3.9
 @schematics/update 0.13.9
 rxjs 6.3.3
 typescript 3.2.4

Now create app from sample app shell below

  ng new my-app

App can be started and home page automatically opens in browser for the below command

 cd my-app
 ng serve --open

File structure of the app will look like as it shown in below image. Also all the code snippets are marked at the top with the filenames.

Angular source structure

Create Product Catalog

The basic building blocks of an Angular application are NgModules, which provide a compilation context for components. An angular app will certainly have one root module that enables bootstrapping in main.ts file as shown below and set of features as modules.

File: src/main.ts

         .catch(err => console.error(err));

NgModule will have components which define the view with template html and css file and shows behaviour based on data. Now AppModule will invoke the src/app/app.module.ts file. In this file the major things are

  • imports - imports the ng module required for the application. browser module imported for different browser platform on dynamic, forms module imported for entering product details.
  • declarations - Components for the module are defined. Appcomponent is the main component and product component responsbile for the catalog.
  • providers - Providers are for providing services
  • bootstrap - main application view, called the root component, which hosts all other app views. Only the root NgModule should set the bootstrap property
    Appcomponent is the root component to be bootstrapped.

File: src/app/app.module.ts

  declarations: [
  imports: [
  providers: [],
  bootstrap: [AppComponent]
  export class AppModule { }

AppComponent is the bootstrap component which will host the view of product catalog by ProductsComponent. Component is the special decorator with template and css styles. Component view will be injected in all the place where app-root(<app-root>) tag is mentioned as it works based on selector attribute mentioned below.

File: src/app/app.component.ts

 import { Component } from '@angular/core';
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
 export class AppComponent {
     title = 'Product Catalog';

 App component template file will be marked up with app product component tag <app-products>

File: src/app/app.component.html

 <div style="text-align:center"> 
 {{ title }}!

Product Entity

Product entity has to be created and set of products should be available to render the view.

File: src/app/Product.ts has been defined as product entity.

  export class Product {
   id: number;
   name: string;
   qty: number;
   brand: string;
   desc: string;

Mock products added as prerequisites for CRUD operations.

File: src/app/mock-products.ts

 import {Product} from './product';

 export var PRODUCTS: Product[] = [
   {id: 11, name: 'Inspiron Laptop', qty: 3, brand: 'Dell',
   desc: 'It is a 14 inch wide screen laptop. Windows OS with Interl Processor 5'},
   {id: 12, name: 'Power X ', qty: 5, brand: 'LG',
   desc: 'It has 2300mAH battery and free mobile cover case'},
   {id: 13, name: 'Keyboard', qty: 7, brand: 'TVS Gold Keyboard',
   desc: 'Its of standard size. It has provision for USB connector'}


CRUD operation

Product component will be invoked to render the html view which has search and add options at the top. Then the card for each product will be appearing by below html template. ngfor directive iterates through products array and create product card. ngIf directive is for toggling the card to view and edit mode. As of now for displaying the card will be in view mode which is based on selectedProduct.

File: src/app/products/products.component.html

 <div class="catalog">
    <div class="card cardsize clickable" *ngFor="let product of products" (click)="onSelect(product)">
    <div *ngIf="selectedProduct!=product" class="card-body">
    <h2 class="card-title">{{ | titlecase}}<button class="delete" (click)="onDelete(product)">X</button></h2>
    <p class="card-subtitle">Product Details</p>
         <p class="card-text"><span class="propertyname">Id:</span>{{}}</p>
         <p class="card-text"><span class="propertyname">Qty:</span>{{product.qty}}</p>
         <p class="card-text"><span class="propertyname">Desc:</span>{{product.desc}}</p>

Search Operation And Add Operation are shown by the below div block

File: src/app/products/products.component.html

  <input [(ngModel)]="searchText" placeholder="product name"/>
  <button class="btn btn-primary" type="button" (click)="onSearch(searchText)">Search Product</button>
  <button class="btn btn-primary" type="button" (click)="onAdd(product)">Add Product</button>

When the card is clicked for edit mode, the card toggles to show up the form for entering the details. Likewise when add product is clicked, new card created with display of the form modules.

File: src/app/products/products.component.html

 <div class="catalog">
    <div class="card cardsize clickable" *ngFor="let product of products" (click)="onSelect(product)">
       <div *ngIf="selectedProduct==product">
          <h2 class="card-title">Create/Edit Product<button class="delete" (click)="onDelete(product)">X</button></h2>
          <form (ngSubmit)="onSubmit(product)">
               <label>Name:</label><input [(ngModel)]="" name="productName placeholder="product name"/>
                <div style="width: 7rem;">
                <label>Qty:</label><input [(ngModel)]="selectedProduct.qty" name="productQty" style="width:3rem;" type="number" placeholder="product qty"/>
                <label>Brand:</label><input [(ngModel)]="selectedProduct.brand" name="productBrand" placeholder="product brand"/>
                <label>Desc:</label><input [(ngModel)]="selectedProduct.desc" name="productDesc" placeholder="product desc"/><br/>
                <input style="float:right; width: 5rem;" type="submit" value="Save" />

Angular html backed up by the angular component which provides the list of products to display. For each operation like delete, add, edit(onselct) event methods has been written in the component.ts. For add and edit, card is in edit mode which invokes submit event method to update the products model.

File: src/app/products/product.component.ts

 import { Component, OnInit } from '@angular/core';
 import { Product } from '../product';
 import { PRODUCTS } from '../mock-products';

    selector: 'app-products',
    templateUrl: './products.component.html',
    styleUrls: ['./products.component.css']

 export class ProductsComponent implements OnInit {

    products = PRODUCTS; /* takes the mock products and display the products for view */

   selectedProduct: Product; /*On click of the card, it takes that product to selectedProduct variable*/

   lastProductId: number; /* it is running counter for the products */

   constructor() {
          this.selectedProduct = null;
          this.lastProductId = this.products.length;

   ngOnInit() {

   /*when click on product card, the selectedProduct is cached by the class member.*/
   onSelect(product: Product) : void {
      console.log("product selected");
      this.selectedProduct = product;

   /* while clicking on add product, the product entity created with available id and pushed to products array. */
   onAdd(product: Product): void {
      console.log("product added");
      product = {id: this.lastProductId, name: '', qty: 0, brand: '', desc: ''};
      this.selectedProduct = product;

  /* while searching, the product name search field value given will be searched in each product name field. */
  onSearch(searchText: string) : void {
      this.products = this.products.filter(p1 =>>=0);

 /* while delete is clicked, the product will be removed from the products modal. */
 onDelete(product: Product) : void {
    this.products = this.products.filter(p1 => p1!=product);

 /* As the product is double binded, when edit or add product is done, it automatically applies to the products model */
  onSubmit(product: Product) {
     this.selectedProduct = null;

When we do ng serve --open inside the project folder, we get screen as below:

angular product view



Code Samples:



Nagappan is a techie-geek and a full-stack senior developer having 10+ years of experience in both front-end and back-end. He has experience on front-end web technologies like HTML, CSS, JAVASCRIPT, Angular and expert in Java and related frameworks like Spring, Struts, EJB and RESTEasy framework. He hold bachelors degree in computer science and he is very passionate in learning new technologies.

Subscribe to our newsletter.

We will send mail once in a week about latest updates on open source tools and technologies. subscribe our newsletter

Related Articles

COVID19 Stats using Angular Material Design

  • angular material-design covid covid-stats

Material design is inspired from the real world building architecture language. It is an adaptable system of guidelines, components, and tools that support the best practices of user interface design. Backed by open-source code, Material streamlines collaboration between designers and developers, and helps teams quickly build beautiful products. In this article, we will build COVID stats using Angular Material design.

Read More

Angular Service Workers Usage Guide

  • angular service-worker offline-app

Web developers come across scenarios like web application completely breaks when workstation goes offline. Likewise to get into our application, every time we need to open a browser and then access it. Instead if it is in app, it will be easy to access for end-user. Push notifications similar to email client need to be done through web application. All these are addressed by a magic called service worker.

Read More

All About Multi-Provider Feature of Angular Version 2.0

  • angular dependency-injection multi-providers

The newly introduced concept of dependency injection in Angular version 2.0 makes it an attractive front-end technology all because of one amazing feature called 'Multi-Providers'. In general, it allows the users to attach certain operations by themselves and a few plugin custom functionality which is not required in our mobile app use case.

Read More

Push Notifications using Angular

  • angular push-notifications notifications

Notifications is a message pushed to user's device passively. Browser supports notifications and push API that allows to send message asynchronously to the user. Messages are sent with the help of service workers, it runs as background tasks to receive and relay the messages to the desktop if the application is not opened. It uses web push protocol to register the server and send message to the application. Once user opt-in for the updates, it is effective way of re-engaging users with customized content.

Read More

Angular Security - Authentication Service

  • angular security authentication jwt

Angular is a framework for creating single page web application. Angular facilitates the security feature and protection mechanism. It provides frameworks by verifying all the routing urls with security authguard interface to validate and verify the user and its permissions.

Read More

JHipster - Generate simple web application code using Spring Boot and Angular

  • jhipster spring-boot angular web-application

JHipster is one of the full-stack web app development platform to generate, develop and deploy. It provides the front end technologies options of React, Angular, Vue mixed with bootstrap and font awesome icons. Last released version is JHipster 6.0.1. It is licensed under Apache 2 license.

Read More

WebSocket implementation with Spring Boot

  • websocket web-sockets spring-boot java

Spring Boot is a microservice-based Java framework used to create web application. WebSocket API is an advanced technology that provides full-duplex communication channels over a single TCP connection. This article explains about how to implement WebSocket using Spring Boot.

Read More

SeoToaster: easy, fast and efficient open source CMS for top SEO performance

  • cms content-management-system seo ecommerce

SeoToaster is a free Open Source CMS & Ecommerce solution to build, manage and market websites optimized for for top search engine performance. As the name implies, Seo Toaster is to date the only content management system (CMS) to truly integrate SEO execution and web marketing automation technology in full compliance with the search engines industry’s best practices.

Read More

Getting Started with Spring Batch

  • spring-batch spring-boot batch-processing

The best way to design a system for handling bulk workloads is to make it a batch system. If we are already using Spring, it will be easy to add a Spring Batch to the project. Spring batch provides a lot of boiler plate features required for batch processing like chunk based processing, transaction management and declarative input/output operations. It also provides job control for start, stop, restart, retry and skip processing also.

Read More

Data dumping through REST API using Spring Batch

  • spring-batch data-dump rest-api java

Most of the cloud services provide API to fetch their data. But data will be given as paginated results as returning the complete data will overshoot the response payload. To discover the complete list of books or e-courses or cloud machine details, we need to call the API page-wise till the end. In this scenario, we can use Spring Batch to get the data page by page and dump it into a file.

Read More

Best open source Text Editors

  • text-editor editor tools dev-tools

Text editors are mainly used by programmers and developers for manipulating plain text source code, editing configuration files or preparing documentation and even viewing error logs. Text editors is a piece of software which enables to create, modify and delete files that a programmer is using while creating website or mobile app.In this article, we will discuss about top 7 all-round performing text editors which is highly supportive for programmers.

Read More

React Patent Clause Licensing issue. Is it something to worry?

  • react react-license facebook

React libraries from Facebook is one of the most used UI libraries. It is competitive to AngularJS. There are many open source UI components or frameworks available but mostly people narrow down to two choices Angular / React. Recently Facebook has updated React license and added a patent clause which makes companies to worry and rethink whether to use React or not.

Read More

Build Consulting Website using Next.js

  • react nextjs website-development ssr

One of the popular web framework for building Single page application (SPA) or static site is React library. Application built with React packages will be rendered completely on the client side browser. If you want to reduce the load on client side browser, we need to pre-render the pages in server (Serer side rendering) and serve it to the client. So the client loads the page like simple html page. Also if the pages are rendered from server then search engine will be able to fetch and extract the pages. To do SSR for React, the best abstraction framework is Next.js. In this blog, we will explain how to build a simple consulting website using NextJS.

Read More

PrestaShop - A feature rich Open Source eCommerce solution

PrestaShop is an Open Source eCommerce Solution. It comes complete with over 310 features that have been carefully developed to assist business owners in increasing sales with virtually little effort. It is being used in more than 150,000 online stores.

Read More

Scene.js - Library to Create Timeline-Based Animation

  • scenejs css timeline javascript animation motion

Scene.js is a JavaScript timeline-based animation library for creating animation websites. As an animated timeline library, it allows you to create a chronological order of movements and positions of objects.

Read More

Top 10 AI development tools which you should know in 2020

  • artificial-Intelligence neural-networks frameworks ai machine-learning

It is a fact the 2020 is not going the way we expected to be but when it comes to technology breakthrough we can say 2020 will be the heir of greatness. <br />Speaking of technical breakthroughs we have got artificial intelligence which is known to be taking over the mankind like a wildfire. Everything around us is connected through AI be it shopping travelling or even reading. Every other activity of ours is transforming into a whole new extent.

Read More

Apache OpenNLP - Document Classification

  • opennlp natural-language-processing nlp document-classification

Apache OpenNLP is a library for natural language processing using machine learning. In this article, we will explore document/text classification by training with sample data and then execute to get its results. We will use plain training model as one example and then training using Navie Bayes Algorithm.

Read More

Getting Started With Django Python Web Framework

  • django python web-framework

Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. It is pre-loaded with user authentication, content administration, site maps, RSS feeds and many more tasks. Security features provided are cross site scripting (XSS) protection, cross site request forgery protection, SQL injection protection, click-jacking protection, host header validation, session security and so on. It also provides in built caching framework.

Read More

Laravel eCommerce Platform - Bagisto

  • ecommerce shopping laravel php

Nowadays on the web, Shopping is one of the most popular activities. Everyone can shop at their recess, anytime from anywhere. However, this is interesting that anyone can have their pages built to display their favourite products and services.

Read More

Build Simple Ecommerce site using React and Jotai

  • ecommerce react jotai

Retail Ecommerce website can be created quickly with React. It can be created using React, Bootstrap, React DOM and Jotai. Data flow within the commerce site is done using Jotai in a light-weight manner. The main workflow of showing all the items in the gallery to user and user adding to the cart will be done as part of this blog.

Read More

We have large collection of open source products. Follow the tags from Tag Cloud >>

Open source products are scattered around the web. Please provide information about the open source projects you own / you use. Add Projects.