angularjs - Angular 2 Http call to Node server not being invoked -
my http call node server not being invoked.
the call initiates following component:
@component({ selector: 'app-special-value', templateurl: './special-value.component.html', styleurls: ['./special-value.component.css'] }) export class specialvaluecomponent implements oninit { constructor(private dataservice: dataservice) { } ngoninit() { this.getspecialvalueproducts(); } getspecialvalueproducts() { this.dataservice.getspecialvalueproducts(); } }
the service's getspecialvalueproducts() called calls node server:
@injectable() export class dataservice { private specialvalueurl = "/api/product/specialvalue"; constructor(private http: http) { } getspecialvalueproducts() { console.log('getspecialvalueproducts() called'); return this.http.get(this.specialvalueurl) .map((response: response) => response.json()) .catch(this.handleerror); } }
the connection database successful. later call data service node function never invoked.
const express = require('express'); const router = express.router(); const mongoose = require('mongoose'); const product = require('../models/product'); module.exports = router; const url = "mongodb://xxxxxx:xxxxxxu@xxxxx.mlab.com:111111/xxxxxx"; mongoose.promise = global.promise; mongoose.createconnection(url, function(err) { if(err) { console.log('error!!!' + err); } else { console.log('connected database!'); } }); router.get('/product/specialvalue', function(req, res) { console.log('get specialvalue called '); product.find({'specialvalue': true}) .sort({'price': 1}) .exec(function(err, products) { if(err) { console.error('error retrieving special value products!'); } else { console.log("products = " + json.stringify(products)); res.json(products); } }) })
node server:
const express = require('express'); const bodyparser = require('body-parser'); const path = require('path'); const api = require('./server/routes/api'); const port = 4200; const app = express(); app.use(express.static(path.join(__dirname, 'dist'))); app.use(bodyparser.urlencoded({extended: true})); app.use(bodyparser.json()); app.use('/api', api); app.get('*', (req, res) => { res.sendfile(path.join(__dirname, 'dist/index.html')); }); app.listen(port, function() { console.log('@@@@ nglowes01 server running on localhost: ' + port); })
Comments
Post a Comment