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.
- Basic knowledge of Angular
- Visual Studio Code must be installed
- Angular CLI must be installed
- Node JS must be installed
Let’s create a new Angular project using the following NPM command,
Now, let’s create a new component by using the following command,
Install ngx-bootstrap from npm by using the folowing command.
Now let’s add bootstrap styles in our index.html file.
For Bootstrap 3,
For Bootstrap 4,
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.
Now, open the ngx-bootstrap-datepicker.component.ts file and add the following code in this file.
Create a service dataservice using the following NPM command
Now, open the data.service.ts file and add the following code,
Now, open the app.component.html file and add the following code in the file,
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.
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.