我是由cli生成的angular2项目。我想在模块下导入使用_.uniq(arr)函数。但我指的是这个库:
./../typings/globals/underscore/index.d.ts.
以下是我尝试使用下划线的组件代码:
import { Component, OnInit } from '@angular/core';
import { Params, IndexService } from '../services/index.service';
import { ActivatedRoute, Router } from '@angular/router';
var sizeof = require('object-sizeof');
var striptags = require('striptags');
// var _ = require("underscore.string");
var s = require("underscore.string");
import * as _ from 'underscore';
@Component({
selector: 'app-analysis-content',
templateUrl: './analysis-content.component.html',
styleUrls: ['./analysis-content.component.css']
})
export class AnalysisContentComponent implements OnInit {
countInfo: {};
percents: number;
countOfKeyword: number;
microdataArray: [];
constructor(private indexService: IndexService, private route: ActivatedRoute) { }
.....
private checkTitleCohance(dom: any) {
var el = this.createDOM(dom);
var title = el.getElementsByTagName('title');
var _title = title[0].innerText;
var res = this.splitString(_title);
var body = this.splitString(this.getContent(dom));
var count = 0;
_.unique(res);