Underscore.js and Angular
Reference: http://underscorejs.org/
Installation and Import
- Node.js > npm install underscore
- import * as _from 'underscore';
In app.component.ts
import * as _ from 'underscore';
import { Component } from '@angular/core';
import * as _ from 'underscore';
@Component({selector: 'app-root',template: `<h1>even: {{even}}</h1>`
})
export class AppComponent { even:any;constructor(){this.test();}
test(){ this.even = _.find([1, 2, 3, 4, 5, 6],
function(num){ return num % 2 == 0; });
}}
import * as _ from 'underscore';
@Component({selector: 'app-root',template: `<h1>even: {{even}}</h1>`
})
export class AppComponent { even:any;constructor(){this.test();}
test(){ this.even = _.find([1, 2, 3, 4, 5, 6],
function(num){ return num % 2 == 0; });
}}
评论
发表评论