0

Here is my code. I am trying to call the header in the routes and controller and it will not work correctly. Please let me know if anyone knows why this is happening. Routes.js:

module.exports = function(app) {
  var http = require("http");

  app.get('/', function(req, res) {
    res.sendfile('./public/index.html');
  });

  app.get('/forumDetailsHeader', function(req, res) {
    // res.setHeader('Content-Type', 'Forum Details Header');
    res.send(JSON.stringify({
      "header": "Forum Details Header"
    }));
  });
};

forumDetailsCtrl.js:

var app = angular.module('huddleBoard');

app.controller('forumDetailsCtrl', ['$scope', '$http',
  function($scope, $http) {
    $scope.header = "";
    // $scope.header = "Forum Details Header";

    $http.get('/forumDetailsHeader').then(function(value) {
      $http.header = value.header;
      console.log('Hello World');
      // res.header('Forum Details Header', 0);
    });

    $scope.lines = [{
      text: 'Name:'
    }, {
      text: 'Schedule:'
    }, {
      text: 'Leader:'
    }, {
      text: 'Facilitator:'
    }, {
      text: 'Dial-in Number:'
    }, {
      text: 'Objective:'
    }];
  }
]);

UPDATE: So, I think there is something that has to deal with the controller side not correctly configuring the $http.get function. If anyone has knowledge of this please help me out. Also, I didn't know if there was something also that has to deal with my html file. When I display the webpage, it is showing {{header}} which is what is called in my html, the following is the html side of all of this, I am just wondering if that needs to be changed as well

<div data-ng-contrller="forumDetailsCtrl">
   <h3 data-ng-model="header">{{header}}</h3>
   <div ng-repeat="line in lines">
       <div class = "preview">{{line.text}}</div>
   </div>
</div>
  • What is meant by header? are you meant forumDetailsHeader API? – Jameel Moideen Jun 30 '17 at 15:10
  • 2
    And when you say "does not work properly" what does this mean? –  Jun 30 '17 at 15:17
  • So when saying it does not work- to my knowledge it should pull up the Forum Details Header that is called in the routes.js and then it is named value and it should then call it in the forumDetailsHeader. Let me know if you need more info – A. Lafollett Jun 30 '17 at 18:21

1 Answers1

0

For nodejs to return json, the content-type should be 'application/json'

something like this will work:

res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({ a: 1 }));

For more detail: Proper way to return JSON using node or Express

Jack Luo
  • 333
  • 3
  • 5