Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何在angular4中导入名称中带有连字符的npm模块_Node.js_Angular - Fatal编程技术网

Node.js 如何在angular4中导入名称中带有连字符的npm模块

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是您可以使用的函

我想在angular4项目中使用
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