Node.js 如何在angular4中导入名称中带有连字符的npm模块
我想在angular4项目中使用Node.js 如何在angular4中导入名称中带有连字符的npm模块,node.js,angular,Node.js,Angular,我想在angular4项目中使用array-to-treenpm模块。但是当我使用import{array to tree}从'array to tree'导入时它给出错误字符串 请帮忙。我猜你可以用: import * as arrayToTree from ‘array-to-tree’ 然后,arrayToTree就是您可以使用的函数。我猜您可以使用: import * as arrayToTree from ‘array-to-tree’ 然后,arrayToTree是您可以使用的函
array-to-tree
npm模块。但是当我使用import{array to tree}从'array to tree'导入时代码>它给出错误字符串
请帮忙。我猜你可以用:
import * as arrayToTree from ‘array-to-tree’
然后,arrayToTree
就是您可以使用的函数。我猜您可以使用:
import * as arrayToTree from ‘array-to-tree’
然后,arrayToTree
是您可以使用的函数。请尝试此功能
import * as arrayToTree from 'array-to-tree';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
dataOne = [
{
id: 1,
name: 'Portfolio',
parent_id: undefined
},
{
id: 2,
name: 'Web Development',
parent_id: 1
},
{
id: 3,
name: 'Recent Works',
parent_id: 2
},
{
id: 4,
name: 'About Me',
parent_id: undefined
}
];
data = arrayToTree(this.dataOne);
constructor() {
console.log(this.data );
}
}
注意:如果您没有将arrayToTree的结果(this.dataOne)分配给变量,那么typescript将抛出错误
[ts] Function implementation is missing or not immediately following the declaration.
(method) AppComponent.arrayToTree(this: any, dataOne: any): any
请试试这个
import * as arrayToTree from 'array-to-tree';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
dataOne = [
{
id: 1,
name: 'Portfolio',
parent_id: undefined
},
{
id: 2,
name: 'Web Development',
parent_id: 1
},
{
id: 3,
name: 'Recent Works',
parent_id: 2
},
{
id: 4,
name: 'About Me',
parent_id: undefined
}
];
data = arrayToTree(this.dataOne);
constructor() {
console.log(this.data );
}
}
注意:如果您没有将arrayToTree的结果(this.dataOne)分配给变量,那么typescript将抛出错误
[ts] Function implementation is missing or not immediately following the declaration.
(method) AppComponent.arrayToTree(this: any, dataOne: any): any