Search results

Getting started with Angular Spinner component

27 Oct 2021 / 3 minutes to read

This section explains the steps to create a simple Spinner and configure its functionalities in Angular.

Getting Started with Angular CLI

The following section explains the steps required to create a simple angular-cli application and how to configure the `Spinner’.


To get started with Syncfusion Angular UI Components, make sure that you have compatible versions of Angular and TypeScript.

  • Angular : 4+
  • TypeScript : 2.6+

Setting up an Angular project

Angular provides an easiest way to setup project using Angular CLI Angular CLI tool.

Install the CLI application globally in your machine.

Copied to clipboard
  npm install -g @angular/cli

Create a new application

Copied to clipboard
  ng new syncfusion-angular-app

Once you have executed the above command you may ask for following options,

  • Would you like to add Angular routing?
  • Which stylesheet format would you like to use?

By default, it install the CSS style base application. To setup with SCSS, pass —style=SCSS argument on create project.

Example code snippet.

Copied to clipboard
  ng new syncfusion-angular-app --style=SCSS

Use below command to Navigate into the created project folder.

Copied to clipboard
  cd syncfusion-angular-app

Install Syncfusion Popups package

Add Syncfusion Angular popups package in your application by using following Command,

Copied to clipboard
npm install @syncfusion/ej2-angular-popups --save
npm i @syncfusion/ej2-angular-popups --save

Adding CSS reference

The following CSS files can be referenced in [src/styles.css] file.

Copied to clipboard
   @import '../node_modules/@syncfusion/ej2-angular-popups/styles/material.css';

The Custom Resource Generator (CRG) is an online web tool, which can be used to generate the custom script and styles for a set of specific components. This web tool is useful to combine the required component scripts and styles in a single file.

Adding Spinner

Initialize the Spinner using “createSpinner” method and show/hide the spinner using “showSpinner” and “hideSpinner” methods accordingly. Set the target to the spinner to render it based on specific target.

The following steps explains you on how to create and how to show/hide your Spinner.

  • Import the “createSpinner” method from “ej2-popups” library into your file as shown in below.
Copied to clipboard
import { createSpinner } from '@syncfusion/ej2-angular-popups';
  • Show and hide this spinner by using “showSpinner” and “hideSpinner” methods for loading in your page and import them in your file as shown in below.
Copied to clipboard
import { showSpinner, hideSpinner } from '@syncfusion/ej2-popups';

Create the Spinner globally

The Spinner can be render globally in a page using public exported functions of the “ej2-popups” package.

Copied to clipboard
import { showSpinner, hideSpinner } from '@syncfusion/ej2-angular-popups';
Copied to clipboard
import { Component } from '@angular/core';
import { createSpinner, showSpinner, hideSpinner } from '@syncfusion/ej2-angular-popups';

  selector: 'app-container',
  template: `<div id="container"></div>`
export class AppComponent {
  constructor() {}

  ngAfterViewInit() {
//createSpinner() method is used to create spinner
  // Specify the target for the spinner to show
  target: document.getElementById('container')

// showSpinner() will make the spinner visible

  // hideSpinner() method used hide spinner
}, 100000);
Copied to clipboard
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';

 * Module
    imports: [
    declarations: [AppComponent],
    bootstrap: [AppComponent],
    providers: [
export class AppModule { }
Copied to clipboard
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

Copied to clipboard
#loader {
    color: #008cff;
    height: 40px;
    width: 30%;
    position: absolute;
    top: 45%;
    left: 45%;

#container {
    height: 100%;
    height: 100px;

#wrapper {
    margin: 0 auto;
    padding-top: 20px;