首页 > 解决方案 > Angular 导入节点包

问题描述

我克隆了这个有角度的项目:https ://github.com/etherparty/explorer

我想在其中安装另一个模块:https ://github.com/miguelmota/ethereum-input-data-decoder

我现在想以角度使用 npm 包的功能。它不起作用。

我采取的步骤:

npm install ethereum-input-data-decoder

试过了,是否有效。不!

然后我在 transactionInfosController.js 文件的第 1 行中添加了导入,因为我想在那里使用新模块。

import { InputDataDecoder } from '../../ethereum-input-data-decoder';

程序部分崩溃并出现错误:

Uncaught SyntaxError: Unexpected token {

我意识到我错误地导入了节点包。

但是查看克隆的 git repo 的文件结构,我没有看到可以导入包的另一个文件。

我需要在哪里放置导入/我需要创建哪个文件?

编辑:需要AngularJS的答案

标签: node.jsangularjsnpmmodulepackage

解决方案


你可以试试这个:

import * as inputDataDecoder from 'ethereum-input-data-decoder'

或者正如托尼指出的那样

import InputDataDecoder as inputDataDecoder from 'ethereum-input-data-decoder'

如果您使用的是 angularjs,请尝试以下操作:

<script src='path_to_node_modules/ethereum-input-data-decoder'></script>

而不是将其导入为:

angular.module('YourApp', ['InputDataDecoder']);

推荐阅读