Angular Projects

Nine professional applications exploring Angular with TypeScript, Ionic, Firebase, and more

A Packt Publishing book by
Zama Khan Mohammed
Zama Khan Mohammed

LEARN ANGULAR THROUGH PROJECTS

The best way to learn a new technology is by using it! In Angular Projects you'll look at a series of applications developed with Angular. You'll go step by step through the development process exploring the framework from different angles, discovering its variety of use cases. By having the opportunity to get your hands dirty, writing code and building actual apps, you'll quickly build your Angular knowledge and use the framework with confidence.
- Minko Gechev, Angular Team Member at Google
Minko Gechev
Angular Projects

Become a Angular expert today.

Get your copy today!

Best Angular practices in one book

A Packt Publication resource that will help you understand the Angular Development process and improve the quality of your work.

1

Setting Up the Development Environment

In this book, we will be covering different kinds of projects, from the basic Angular app to a server-rendered one, and a native app for Android and iOS. We will also look at how to create a component library for our enterprise applications and start testing our components. We will be using different Angular component libraries and tools and get a holistic view of Angular Framework and its capabilities.

Angular apps are written using web technologies. In order to run Angular apps, we need to install Node.js on our machine, which is what we will be doing in this first chapter.

Angular is a framework for building mobile and web applications. It uses TypeScript, which is a superscript of ECMAScript. It adds support for types in JavaScript, which makes the development of Angular apps easier at compile time. We will look into some basic concepts of TypeScript in this chapter, which will explain some of the syntax that we will be using in this book.

Another tool we will look at is Angular CLI, the command-line interface program that the Angular team has created to help with the development and maintenance of Angular apps.

We could write Angular apps using a simple text editor, but to get full productivity out of building our Angular application, we will be using VS Code. Instead of being an Integrated Development Environment (IDE), it's a code editor with rich extension support. In this chapter, we will use VS Code and install the required extensions to make Angular development faster.

The following topics will be covered in this chapter:

  1. Installing Node.js
  2. Understanding the basics of TypeScript
  3. Introducing Angular CLI
  4. Introducing Angular Console
  5. Installing VS Code and installing various extensions
  6. Installing Augury and looking at various sections that help us debug our application
2

Building a Flashcard Game using Angular

In this chapter, we will develop a basic Angular app for a flashcard game. We will also introduce some of the built-in attributes and structural directives in the Angular framework and create a basic template-driven form so that we can add/edit the flashcards. We will be introduced to observables and learn how to use the async pipe to get observable data on the page. We will also create a basic FlashService to perform all the operations related to adding, editing, and deleting flashcards.

The following topics will be covered in this chapter:

  1. Creating a new Angular project and a component
  2. Introducing template-driven forms
  3. Introducing services
  4. Introducing observables
3

Building a Personal Blog Using Angular Router and WordPress

In this chapter, we will create a personal blog using Angular. We will create it as a singlepage application (SPA) using Angular Router. SPAs have the benefit of loading most of an application on their initial load, which is crucial when you are browsing a website. When going from one page to another, an SPA doesn't have to download the whole page; instead, it requests the required API for the page, which is way faster. You will also learn how to configure multiple environments for the project, optimize the SPA using lazy loading routes, and animate routes and elements in Angular applications.

The following topics will be covered in this chapter:

  1. Setting up a WordPress server
  2. Setting up an Angular project with the Angular CLI
  3. Adding multiple routes to our application
  4. Calling the WordPress API
  5. Implementing the lazy loading route
  6. Introducing pre-loading strategy
  7. Adding animations
4

Building an Inventory Application Using Reactive Forms

In this chapter, we will be creating an application for managing an inventory using one of the third-party component libraries that was created by VMware's team, known as the Clarity component. It follows the Clarity Design System, which has detailed UX/UI guidelines that need to be followed for using the components correctly. It also documents do's and don'ts for using each of the components. You can find the documentation at https:/ / clarity. design.

Throughout this chapter, we will be displaying products and performing Create, Read, Update, and Delete (CRUD) operations. In this project, we will also be using reactive forms and creating a complex form via a step-by-step workflow using Clarity's wizard component. We will be using some built-in validations from Angular and will also be creating a custom validator.

The following topics will be covered in this chapter:

  1. Understanding reactive forms
  2. Using reactive forms
  3. Adding built-in and custom validations
  4. Optimizing the bundle
5

Building a PWA E-Commerce Application Using Angular Service Worker

In this chapter, we will be creating an e-commerce application for an electronic store, and then we will convert it into a Progressive Web App (PWA), add support for offline usage, and also add the web app as an application on the home screen on both Android and iOS. We will also set up a Nest.js application so that we can get data from MongoDB.

The following topics will be covered in this chapter:

  1. We will create a Nest.js application for a backend service
  2. We will use Angular Material to create a simple e-commerce application
  3. We will use Lighthouse to measure and analyze our application for PWA
  4. We will convert our application so that it scores a perfect 100 on the Lighthouse for PWA
  5. We will make our application run offline
  6. We will deploy our application on Firebase Hosting
6

Building an Auditing application using Angular and Ionic

In this chapter, we will be using the Firebase Realtime Database to create a Native application that runs on iOS and Android. This will use the Ionic 4 framework. We will also be using ngx-formly in order to create a dynamic form without having to write an HTML code for the whole form.

The following topics will be covered in this chapter:

  1. Exploring the Ionic framework
  2. Getting started with the Ionic CLI
  3. Theming an Ionic application
  4. Setting up Firebase
  5. Getting data from the Firebase Realtime Database
  6. Creating dynamic forms using ngx-formly
  7. Using Ionic Native so that we can use a camera
  • 7

    Building a Server-Side Rendering Application Using Angular

    In this chapter, we will continue to work on our personal blog from Chapter 3, Building a Personal Blog Using Angular Router and WordPress, where we created a Single-Page Application (SPA) using Angular Router. We will render the application on the server so that the performance and the search engine's optimization can be optimized. We will use TransferState to make sure that the APIs are cached when rendered in the server so that the APIs are not called redundantly on the client. We will use different forms of Search Engine Optimization (SEO) to make it discoverable on search engines and so that it can be shared properly on social media platforms such as Twitter, Facebook, and LinkedIn.

    The following topics will be covered in this chapter:

    1. Understanding Angular Universal
    2. Deployment and performance analysis
    3. Adding Universal support
    4. Transferring state from the server to the client
    5. Deployment and performance analysis of Server-Side Rendering (SSR)
    6. Understanding SEO optimizations
    7. Social media scraping
    8

    Building an Enterprise Portal Using Nx, NgRx, and Redux

    In this chapter, we will be creating an enterprise application for admins so that they can log in and check the sales of the e-commerce application we've developed. We will be using OAuth, along with Auth0, to authenticate users of our application and check the sales of each product using D3 visualizations. We will be using the Nx workspace to create our monorepo application, which will include not only our e-commerce application and admin application, but also libraries that can be shared by them.

    The following topics will be covered in this chapter:

    1. Exploring the monorepo application
    2. Redux using NgRx
    3. Understanding token-based authentication
    4. Adding an authentication library
    5. Using ngx-charts for D3 visualizations
    9

    Building Multi-language NativeScript Application with Angular

    In this chapter, we are going to develop a NativeScript application with the use of Angular to display news posts. We will allow the user to select from a range of different languages and display the news in the selected language. We will be mocking the API to fetch news posts in different languages. We will use two languages—English and Spanish—and use ngx-translate to add internationalization to our application. We will do this by using a NativeScript plugin for use as a Native Snackbar.

    The following topics will be covered in this chapter:

    1. Introducing NativeScript Playground
    2. Creating your first NativeScript with an Angular application
    3. Exploring UI layout containers
    4. Implementing internationalization using ngx-translate
    5. Adding a NativeScript plugin to our application
    10

    Building a Component Library Using Angular CDK and Elements

    In this chapter, we will build a component library that can be used not only in our applications but can also be published on npm so that it can be used by any other applications that want to use our component library. Reusable component libraries are something that make teams build awesome applications super fast. We will be building a drop-down reusable component library that will be so flexible that it can be used multiple times in the application.

    The following topics will be covered in this chapter:

    1. Understanding Angular CDK
    2. Creating drop-down functionality
    3. Adding accessibility support
    4. Publishing a library on npm
    5. Introducing Angular elements
    11

    Testing Angular Application using Jasmine, Jest and Protractor

    In this chapter, we will cover one of the important topics in software development, that is, testing applications, and why it is important. We will start with an existing application that was built using the Angular CLI and we will make sure that all the existing tests pass. Then, we will add a new isolated test case and some deep integration testing to our application. We will then move on to running a code coverage report and setting thresholds for our coverage report. Afterward, we will move on to updating our tests, using Jest as the test runner to make the testing experience delightful. We will end this chapter by adding some end-to-end (e2e) tests to test the application.

    The following topics will be covered in this chapter:

    1. Why test our web applications?
    2. Isolated unit testing
    3. Deep integration tests
    4. Deep integration tests for the component
    5. Deep integration tests for the service
    6. Understanding code coverage
    7. Using Jest with the Angular CLI
    8. Snapshot testing
    9. End-to-end testing
    10. Custom error handling

    BENEFITS

    What you can learn with this Angular Book

    Best practices

    The book follows the best practices that are approved by Angular Team.

    Processes and tools

    It showcases different tools that allow for the highest level of cooperation and the highest quality of work.

    TOOLS

    Tools used in the book!

    Angular

    Angular

    Animations

    Animations

    Augury

    Augury

    CDK

    CDK

    CLI

    CLI

    Forms

    Forms

    HTTP

    HTTP

    Language Services

    Language Services

    Material

    Material

    Router

    Router

    Universal

    Universal

    Formly

    Formly

    Clarity Design

    Clarity Design

    Momentum Design

    Momentum Design

    Angular Console

    Angular Console

    VSCode

    VSCode

    Zeit Now

    Zeit Now

    Auth 0

    Auth 0

    Ionic

    Ionic

    NGRX

    NGRX

    NX

    NX

    NativeScript

    NativeScript

    RXJS

    RXJS

    ngx-translate

    ngx-translate

    Firebase

    Firebase

    ngx-seo

    ngx-seo

    PWA

    PWA

    Karma

    Karma

    Protractor

    Protractor

    Element

    Element

    Jest

    Jest

    Bootstrap

    Bootstrap

    Zama Khan Mohammed

    Hi, I'm Zama Khan Mohammed, the author of the book

    Zama Khan Mohammed is a Software Architect, building Enterprise Web Applications with more than 7 years of experience. He has a Master’s Degree in Computer Science and has loads of experience in Software Development using technologies such as Angular, React, AWS etc. He has a keen interest in Software Development as well as Machine Learning, and he feels passionate about teaching and mentoring his interests to others.

    Questions?
    Shoot me a quick tweet &
    I’d be happy to help you.

    SPECIAL THANKS

    I dedicate this book to my family, my wife, my parents, and my son, who was born during the writing process. I would also like to give a special dedication to my friends Saad Ather, Mohammed Abdul Kareem, and Ruman ul Hassan, who kept me motivated and helped me along the way.
    Tekzenit IncTekzenit Inc. - all my colleagues
    Momentum UI Design Team. https://momentum.design/
    Packt Logo Packt Team - specially Jane D'souza, Aamir Ahmed and Smit Carvalho