Introduction

In this article, we are going to learn the use of Ngx-Bootstrap DateRange Picker and Date Picker in Angular 8.

Ngx-Bootstrap has released a package of open-source tools which is native Angular directives for Bootstrap 3 and 4. It contains all core components powered by Angular. In this article we will learn about DatePicker component which is a cool feature of Ngx-bootstrap.

Prerequisites

  • Basic knowledge of Angular
  • Visual Studio Code must be installed
  • Angular CLI must be installed
  • Node JS must be installed

Step 1 

Let’s create a new Angular project using the following NPM command,

Step 2

Now, let’s create a new component by using the following command,

   

Step 3

 Install ngx-bootstrap from npm by using the folowing command.

Or,

Step 4

 Now let’s add bootstrap styles in our index.html file.

For Bootstrap 3,

For Bootstrap 4,

Step 5

Let add the template in our ngx-bootstrap-datepicker.component.html.

In bsConfig method we can format the date and time. showWeekNumbers is a boolean value which is true by default and displays the number of the week.

Also we can select the min date. max date, etc. 

Step 6

Now, open the ngx-bootstrap-datepicker.component.ts file and add the following code in this file.

Step 7

Create a service dataservice using the following NPM command

Now, open the data.service.ts file and add the following code,

Step 8

 Now, open the app.component.html file and add the following code in the file,

Step 9

Let’s open app.module.ts file and add the following code in the file,

Now it’s time for the output,

Date range picker is where we can select a range of datess. After selecting date one event will fire which is an array,

The below image shows that it will fetch only those data which comes in the range from April 1 to April 14. 

The below image shows the normal ngx-bootstrap datepicker. 

  

Conclusion

I hope you have enjoyed this article as much as I have enjoyed writing and coding the examples.

Please let me know how to improve it.



Source link

Write A Comment