Alireza Valizade Alireza Valizade - 1 year ago 1325
TypeScript Question

how to use underscore.js library in angular 2

I'm trying to create an application with angular 2,and want use underscore.js library in my .ts files ,for example when i want use this function :

let myId =[5, 4, 3, 2, 1]);

is not define and throw error and i dont want use
declare var _ : any;
in my module

Answer Source

You have to Add TypeScript Definitions for Underscore:

tsd install underscore

Configure SystemJS

  paths: {
    underscore: ‘./node_modules/underscore/underscore.js’

Finally import the Module

import * as _ from ‘underscore’;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download