March 2017
Intermediate to advanced
821 pages
18h 21m
English
To populate our template, we need to generate some random search result data. For this, we can use the Chance.js library. We will generate random data on the server side, not on client side, so that we can later demonstrate how to make an HTTP request using Angular 2.
Chance.js is available for both client-side and server-side JavaScript. We earlier downloaded the Chance.js package to use with Node.js. Here is the code to generate random data. Place it in the app.js file above the /* route so that /* doesn't override the random data route:
var Chance = require("chance"), chance = new Chance(); app.get("/getData", function(httpRequest, httpResponse, next){ var result = []; for(var i = 0; i < 10; i++) { result[result.length] ...Read now
Unlock full access