How to import functions or variables from node.js file in AngularJs or Angular?

142 Views Asked by At

Hi I am working with IOTA distributed ledger. I have iota client library for node.js. I want to read data from node.js file where I access IOTA distributed ledgers and pass it to Html where user can see.

My client.js file:

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);
});

I want to pass x[i] variable to 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> 

I know how to read data from controller but how am I gonna read data if client.js has imported libraries. I tried in Angular to convert libraries to typescript but couldnt figure out.

1

There are 1 best solutions below

0
On

This is typically done in package.json, such as server or build