Integrating Ladda buttons in Angular 2

Whenever we perform any server-side operation or any logic which takes a certain time to execute, at that time generally we use some loading icon. This is to indicate that operation is in progress. Well in order to increase the user experience we can use ladda buttons. In this article, we will be Integrating Ladda buttons in Angular 2.

You can find ladda buttons modules for Angular 2 from here. In this article, I will try to cover all the possible uses of ladda buttons.






Setting up our Application

Let’s use Angular CLI to setup our application. If you don’t have Angular CLI installed on your machine run the below command to install it globally.
npm install -g angular-cli
After Angular CLI installation, to create a new Angular project Run below command. This command will create all the necessary files, download all the required external dependencies and do all of the setup work for us.

ng new AppName

Installing and configuring angular2-ladda module:

First, you need to install this module from NPM, run the below command and save it into your package.json file,

Above command will download and install the angular2-ladda module and at the same time, save it to package.json as a dependency.

Now installation is complete, let’s import this module in our application so, to do that open file app.module.ts and import the angular2-ladda shown below.


The Application

Below is the very simple example of angular2-ladda. In the below code,

We have a button when we click on that button, submit function will be called. Inside the submit function, well the code is self-explanatory.


Progress bar in ladda buttons

In the below code,

In the button markup, I have added data-style attribute having value as expand-left, which shows ladda spinner to the left.

Inside the progressClick() function, to show the progress bar I am updating the value of isLoadingProgessLeft property of the class AppComponent.


Well, as of now that’s it. But I would recommend you to download the source of this article because it contains a lot of examples. So till then Happy reading.