我是Angular2的初学者。我想使用第3方库中的函数,但得到“ xxx不是函数”。
这是“ app.component.ts”中的代码:
import { Component, OnInit } from '@angular/core';
import { arrayShuffle } from "array-shuffle";
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
name = 'Angular';
list: string[] = [];
ngOnInit() {
this.list.push("C value");
this.list.push("B value");
this.list.push("A value");
console.log("list: " + this.list);
const shuffled = arrayShuffle(this.list);
console.log("list: " + this.list);
}
}
This is the whole thing on stackblitz
我怎么了?
答案 0 :(得分:2)
从
更改导入行import { arrayShuffle } from "array-shuffle";
到
import arrayShuffle from "array-shuffle";