【问题标题】:How to import functions or variables from node.js file in AngularJs or Angular?如何从 AngularJs 或 Angular 中的 node.js 文件导入函数或变量?
【发布时间】:2021-10-18 09:31:11
【问题描述】:

您好,我正在使用 IOTA 分布式账本。我有 node.js 的 iota 客户端库。 我想从访问 IOTA 分布式账本的 node.js 文件中读取数据并将其传递给用户可以看到的 Html。

我的 client.js 文件:

const Iota = require('@iota/core');
const Extract = require('@iota/extract-json');
const iota = Iota.composeAPI({
    provider: 'https://nodes.devnet.iota.org:443'
    });
let x = [];
iota.getBundlesFromAddresses(['PXMPEGYZCOVEOSRAUXY9VYRBHJBSDWORWQNBDJRVEFTMXZWLTQZSPHEUDMXT9YKGPMMSVDSNHSJNWQUOX'])
.then(bundle => {
    for (let i = 0; i < bundle.length; i++) {
        console.log(JSON.parse(Extract.extractJson(bundle[i])).message);
        x[i]=JSON.parse(Extract.extractJson(bundle[i])).message;
        } 
})
.catch(err => {
    console.error(err);
});

我想将 x[i] 变量传递给 html。

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="client">
    {{ x[0]}}
    {{ x[1]}}
    {{ x[2]}}
</div>

<script src="myApp.js"></script>
<script src="client.js"></script>

</body>
</html> 

我知道如何从控制器读取数据,但是如果 client.js 已经导入了库,我将如何读取数据。 我尝试在 Angular 中将库转换为打字稿,但无法弄清楚。

【问题讨论】:

    标签: javascript node.js angular angularjs iota


    【解决方案1】:

    这通常在 package.json 中完成,例如 server 或 build

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-21
      • 1970-01-01
      • 2017-11-01
      • 2019-09-19
      • 1970-01-01
      • 2017-05-16
      • 2019-01-25
      • 1970-01-01
      相关资源
      最近更新 更多