node.js - Unable send data from backend(nodejs) to frontend(angular2) -
i have data queried elasticsearch through nodejs , want send frontend. when try shows me error below.
error error: uncaught (in promise): response status: 0 url: null @ resolvepromise (zone.js:783) @ zone.js:709 @ rejected (messages-component.js:14) @ zonedelegate.invoke (zone.js:391) @ object.oninvoke (ng_zone.ts:296) @ zonedelegate.invoke (zone.js:390) @ zone.run (zone.js:141) @ zone.js:831 @ zonedelegate.invoketask (zone.js:424) @ object.oninvoketask (ng_zone.ts:288)
back-end looks this,
var name = ".class"; rama(); function rama() { 'use strict'; const elasticsearch = require('elasticsearch'); const esclient = new elasticsearch.client({ host: '127.0.0.1:9200', log: 'error' }); const search = function search(index, body) { return esclient.search({index: index, body: body}); }; const test = function test() { let body = { size: 20, from: 0, query: { match: { jarfilename: { query: 'cambioclient.jar' } } } }; search('clsdex', body) .then(results => { results.hits.hits.foreach((hit, index) => name="test"); }) .catch(console.error); }; test(); }; var express = require('express'); var app = express(); var messages = [{text: name, owner: 'tim'},{text: 'other message', owner:'jane'}]; app.use((req, res, next) => { res.header("access-control-allow-origin", "*"); res.header("access-control-allow-headers", "origin, x-requested-with, content-type, accept"); next(); }) app.get('/messages', (req, res) => { res.json(messages); }) app.listen(11500);
this part in front-end(message-component.ts) receiving results,
import { component } '@angular/core'; import { webservice } './web.service'; @component({ selector: 'messages', template: ` <div *ngfor="let message of messages"> <md-card style="margin:8px"> <md-card-title>{{message.owner}}</md-card-title> <md-card-content>{{message.text}}</md-card-content> </md-card> </div> ` }) export class messagescomponent { messages = []; constructor(private webservice: webservice) {} async ngoninit() { var response = await this.webservice.getmessages(); this.messages = response.json(); } }
where mistaken this? please me figure out.
Comments
Post a Comment