1

When i use this code, work and i get tem response "ok":

controller.js

    var myApp = angular.module('myApp',[]);

myApp.controller('AppController',['$scope','$http',function($scope,$http){

    $http.get('/').
        success(function (response) {
        console.log("ok");
    });

}]);

server.js

var express = require('express');
var app = express();

app.use(express.static(__dirname + "/public"));

app.get('/', function (req, res){

    var person1 = {
        name: 'Tim',
        email:'[email protected]',
        number:'32232233'
    };

    var person2 = {
        name :'Dani',
        email:'[email protected]',
        number:'22222222'
    };

    var contactList = [person1,person2];

    res.json = contactList;
    console.log("send work");
});

app.listen(3000);
console.log("Server running on port 3000");

but, when i change $http.get('/') to $http.get('/list') and app.get('/', function (req, res) to app.get('/list', function (req, res) not works.

The get time 'list' stay Pending for ever, and when i stop node server i get "GET http://localhost:3000/list net::ERR_EMPTY_RESPONSE".

1
  • res.json(contactList); Commented Feb 10, 2015 at 0:01

1 Answer 1

2

You aren't actually calling the res.json() method.

Make sure you are actually invoking the method rather than assigning it to equal the contact list:

res.json(contactList);

vs.

res.json = contactList

In context:

app.get('/list', function (req, res){

    var person1 = {
        name: 'Tim',
        email:'[email protected]',
        number:'32232233'
    };

    var person2 = {
        name :'Dani',
        email:'[email protected]',
        number:'22222222'
    };

    var contactList = [person1,person2];

    res.json(contactList);
    console.log("send work");
});

The reason you are probably getting a response on '/' is because your app is hosted on '/', so you are going to get a response.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.