It is easier than you may think - the only you need to do is just add two dependencies to your package.json file.
Step 1. Install dependencies
You can do this with npm command.
npm install --save @types/underscoreand next
npm install --save underscore
Step 2. Use it
In order to useunderscore library in your component or service class you have to import library in the following way:
import * as _ from "underscore";That is basically all - now you can take all the goodies from underscore. For example, to fetch all unique key values from an array of key-value struct we can do this way:
public uniqueKeys(input: {[key: string]: string}[]): string[] {
let keys = _
.chain(input)
.map(a => _.keys(a))
.flatten()
.uniq(false)
.value()
Brak komentarzy:
Prześlij komentarz