Привет, у меня есть на данный момент поддельный backend с httpbackend в моем угловом проекте. Но я хочу перенести свой поддельный backend на серверный узел js, но я не знаю.AngularJs Server Node js/get
Так На данный момент у меня есть это:
var express = require('express')
, path = require('path')
, fs = require('fs')
, bodyParser = require('body-parser')
, morgan = require('morgan');
var apps = express();
var staticRoot = __dirname + '/';
apps.set('port', (process.env.PORT || 3000));
apps.use(express.static(staticRoot));
apps.use(bodyParser.urlencoded({ extended: false }));
apps.use(bodyParser.json());
apps.use(morgan('dev'));
apps.use(function (req, res, next) {
var ext = path.extname(req.path);
if (ext !== '') {
return next();
}
});
apps.get('/getTpl', function (req, res) {
res.writeHead(200);
res.end(JSON.parse(["tp1", "tp2", "tp3", "tp4", "tp5", "tp6", "tp7"]));
});
apps.listen(apps.get('port'), function() {
console.log('serveur en route, port : ', apps.get('port'));
});
Мой контроллер:
ctrl.tpls = [];
ctrl.tplJson = undefined;
diapoService.getTpl().then(function (response) {
ctrl.tpls = JSON.stringify(response.data);
console.log(response.data);
});
function getTpl() {
return $http({
method: 'GET'
, url: '/getTpl'
});
Я хочу отправить массив в мой выбор, но мой выбор пуст, почему? пожалуйста
Большое вам спасибо за ваш ответ
Вместо res.writeHead и res.end использовать res.json (JSON.parse (....)); – Molda
спасибо, но он до сих пор не работает –