Spinner and progress in Angular Progress Button component

16 Feb 202412 minutes to read

Change spinner position

Spinner position can be changed by modifying the position property of spinSettingsModel. By default, the spinner is positioned at the left of the ProgressButton. You can position it at the left, right, top, bottom, or center of the text content.

Change spinner size

Spinner size can be changed by modifying the width property of spinSettingsModel. In this demo, the width is set to 20 to change the spinner size.

Spinner template

You can use custom spinner by specifying the template property of spinSettingsModel with custom styles.

The following sample demonstrates the above functionalities of the spinner.

import { Component } from '@angular/core';
import { SpinSettingsModel } from '@syncfusion/ej2-angular-splitbuttons';

@Component({
    selector: 'app-root',
    template: `<div class="e-section-control">
                <!-- To render progress button. -->
               <button ejs-progressbutton content='Submit' [spinSettings]='spinSettings'></button></div>`
})

export class AppComponent {
    public spinSettings : SpinSettingsModel = { position: 'Right', width: 20, template: '<div class="template"></div>'  };
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ProgressButtonModule } from '@syncfusion/ej2-angular-splitbuttons';
import { AppComponent } from './app.component';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        ProgressButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Progress

Content animation

The content of the ProgressButton can be animated during progress using the effect property of animationSettingsModel. You can also set custom duration and timing function using the duration and easing properties. The possible effect values are None, SlideLeft, SlideRight, SlideUp, SlideDown, ZoomIn, and ZoomOut.

import { Component } from '@angular/core';
import { SpinSettingsModel, AnimationSettingsModel } from '@syncfusion/ej2-angular-splitbuttons';

@Component({
    selector: 'app-root',
    template: `<div class="e-section-control">
                <button ejs-progressbutton content='Slide Left' [enableProgress]='true' [animationSettings]= 'animationSettings' [spinSettings]='spinSettings'></button></div>`
})

export class AppComponent {
    public spinSettings : SpinSettingsModel = { position: 'Center' };
    public animationSettings : AnimationSettingsModel = { effect:'SlideLeft', duration: 500, easing: 'linear' };
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ProgressButtonModule } from '@syncfusion/ej2-angular-splitbuttons';
import { AppComponent } from './app.component';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        ProgressButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Change step of the ProgressButton

The progress can be visualized at the specified interval by changing the step property in the begin event of the ProgressButton. In this demo, the step property is set to 20 to show progress at every 20% increment.

import { Component } from '@angular/core';
import { ProgressEventArgs } from '@syncfusion/ej2-angular-splitbuttons';

@Component({
    selector: 'app-root',
    template: `<div class="e-section-control">
                <button ejs-progressbutton content='Progress Step' [enableProgress]='true' (begin)='begin($event)' cssClass='e-hide-spinner'></button></div>`
})

export class AppComponent {
    public begin(args: ProgressEventArgs): void {
        args.step = 20;
    }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ProgressButtonModule } from '@syncfusion/ej2-angular-splitbuttons';
import { AppComponent } from './app.component';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        ProgressButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

The class e-hide-spinner hides the spinner in the ProgressButton, For more information, see hide spinner section.

Change progress dynamically

The progress can be changed dynamically by modifying the percent property in the ProgressButton events. In this demo, on 40% completion of progress, the percent property is set to 90 to show dynamic change of the progress.

import { Component } from '@angular/core';
import { ProgressEventArgs } from '@syncfusion/ej2-angular-splitbuttons';

@Component({
    selector: 'app-root',
    template: `<div class="e-section-control">
                <button ejs-progressbutton [content]='content' [enableProgress]='true' [duration]='15000' (begin)='begin($event)' (progress)='progress($event)' (end)='end($event)' cssClass='e-hide-spinner'></button></div>`
})

export class AppComponent {
    public content: string = 'Progress';

    public begin(args: ProgressEventArgs): void {
        this.content = 'Progress ' + args.percent + '%';
    }

    public progress(args: ProgressEventArgs): void {
        this.content = 'Progress ' + args.percent + '%';
        if (args.percent === 40) {
            args.percent = 90;
        }
    }

    public end(args: ProgressEventArgs): void {
        this.content = 'Progress ' + args.percent + '%';
    }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ProgressButtonModule } from '@syncfusion/ej2-angular-splitbuttons';
import { AppComponent } from './app.component';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        ProgressButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

The method dataBind applies the property changes immediately to the component.

Start and stop methods

You can pause and resume the progress using the stop and start methods, respectively. In this demo, clicking the ProgressButton will pause and resume the progress.

import { Component, ViewChild } from '@angular/core';
import { ProgressButtonComponent } from '@syncfusion/ej2-angular-splitbuttons';

@Component({
    selector: 'app-root',
    template: `<div class="e-section-control">
                <button #progressBtn ejs-progressbutton [content]='content' [enableProgress]='true' [duration]='4000' (end)='end()' [iconCss]='iconCss' cssClass='e-hide-spinner' (click)="btnClick()"></button></div>`
})

export class AppComponent {
    @ViewChild('progressBtn')
    public progressBtn : ProgressButtonComponent | any;
    public content: string = 'Download';
    public iconCss: string = 'e-btn-sb-icon e-download';

    public end(): void {
        this.content = 'Download';
        this.iconCss = 'e-btn-sb-icon e-download';
    }

    public btnClick(): void {
        if(this.content === 'Download') {
            this.content = 'Pause';
            this.iconCss = 'e-btn-sb-icon e-pause';
        }
        else if(this.content === 'Pause') {
            this.content = 'Resume';
            this.iconCss = 'e-btn-sb-icon e-play';
            this.progressBtn.stop();
        }
        else if(this.content === 'Resume') {
            this.content = 'Pause';
            this.iconCss = 'e-btn-sb-icon e-pause';
            this.progressBtn.start();
        }
    }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ProgressButtonModule } from '@syncfusion/ej2-angular-splitbuttons';
import { AppComponent } from './app.component';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        ProgressButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

See Also