A node.js server gives "This is a string". (writeHeader, write( string), end).
When performing a $http request, I see that the node.js server is responding and sending the information back.
In Angular I perform the following request:
angular.module('phoneList').
component('phoneList', {
templateUrl: 'phone-list/phone-list.template.html',
controller: function PhoneListController($http) {
var self = this;
$http.get('http://127.0.0.1:8081/echo').then(function(response) {
self.data = response.data;
}, function(err) {
self.error = err;
self.status = response.status;
self.statusText = response.statusText;
});
}
});
Response
{"data":null,"status":-1,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"http://127.0.0.1:8081/echo","headers":{"Accept":"application/json, text/plain, /"}},"statusText":""}
I tried both just sending JSON from node.js or HTML-text. No difference.
Please consult the official Angular docs for $http. It states the following:
Also, status codes less than -1 are normalized to zero. -1 usually means the request was aborted, e.g. using a config.timeout.
So I guess it is a problem with your backend. Maybe take a look in the developer console to check if the request reaches your server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With