1

In our process to learn Angular2 . we are trying to use api done by marvel . The access to this api is done with hash key that we need to send to the api but we don't really know how to implement

On the running process we the error:

require is not defined

Here is the piece of code:

generateMarvelAccessUrl(baseurl: string) {

    var CryptoJS = require("crypto-js");

    var PRIV_KEY = "mypublickey";
    var API_KEY   = "myprivatekey";

    var url = baseurl + "?limit=100&apikey=" + API_KEY;
    var ts = new Date().getTime();
    var hash = CryptoJS.createHash('md5').update(ts + PRIV_KEY + API_KEY).digest('hex');
    url += "&ts=" + ts + "&hash=" + hash;
    return url;
}

Is someone may help us on this item.

1 Answer 1

1

The require function is provided by SystemJS. You need to add it into your script:

<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script> 
<script src="node_modules/rxjs/bundles/Rx.umd.js"></script>
<script src="node_modules/angular2/bundles/angular2-all.umd.js"></script>

Here is a plunkr describing a working sample:https://plnkr.co/edit/JXLDFBW4A1mi9tyNHoJ3?p=preview

From : https://stackoverflow.com/a/34874540/3279156

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.