![]() |
VOOZH | about |
Lodash is an open-source library that helps in performing operations on various data structures like arrays, or objects, seamlessly and efficiently. When used with javascript frameworks, like angular, it can ease the life of developers while writing functions to manipulate arrays or objects. In this article, we will learn how to use Lodash in angular applications.
Angular has many built-in features for handling data binding, services, and directives, but it lacks a comprehensive utility library for tasks such as array manipulation, deep object inspection, or throttling. Lodash helps fill this gap by providing:
First, create an angular app using the below command:
ng new angular-lodoash
cd angular-lodoash
Next, install the lodash library, and its types:
npm install lodash
npm install @types/lodash --save-dev
"dependencies": {
"@angular/animations": "^16.2.0",
"@angular/common": "^16.2.0",
"@angular/compiler": "^16.2.0",
"@angular/core": "^16.2.0",
"@angular/forms": "^16.2.0",
"@angular/platform-browser": "^16.2.0",
"@angular/platform-browser-dynamic": "^16.2.0",
"@angular/router": "^16.2.0",
"lodash": "^4.17.21",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.13.0"
}
In this step, we will use the lodash filter method to filter even number, and then display it in the UI.
Now, update the template code to display the chunked array in the UI
Run the application using the below command, and go to http://localhost:4200/
ng serve