使用 mongoose 和 angular 获取请求格式

GET request format using mongoose and angular

关于 getRooms 函数,我希望 console.log 在部分页面加载 (/rooms) 时,对象数组包含我的猫鼬模型 (Room) 概述的房间名称、版主和描述和数据库中的数据,以便我可以将其中一些信息呈现给页面。相反,我正在控制台记录似乎是我的 index.html 代码作为客户端的响应,并且永远不会到达服务器。我的 POST 和 PUT 请求正在运行,虽然这是基本的,但我似乎不明白如何正确地发出这个 GET 请求。如果有人可以告诉我如何正确完成此操作,我将不胜感激。

//roomController.js
    angular.module('chatApp').controller('roomController', ['$scope','$http','$location', '$cookies', function($scope, $http, $location, $cookies){

    // $scope.rooms = [
    //   {'name': 'Biology', 'description': 'Discuss the wonders of Bio'},
    //   {'name': 'Literature', 'description': 'From Steinbeck to Shakespeare'},
    //   {'name': 'Dark Souls 3', 'description': 'Discuss gameplay from DS3'},
    //   {'name': 'The Life of Pablo', 'description': "Discuss Kanye West\'s the Life of Pablo"},
    //   {'name': 'Daredevil', 'description': 'Discuss the Netflix original Daredevil'},
    //   {'name': 'React JS', 'description': 'Discuss ReactJS projects'}
    // ];


  $scope.getRooms = function(){
      $http.get('/rooms').then(function(response){
        $scope.roomCount = response.data.length;
        console.log(response.data.length);
        console.log(response);
      });

  };

  $scope.createRoom = function(){
    var newRoom = {
      roomName: $scope.roomName,
      moderator: $cookies.get('currentUser'),
      description: $scope.roomDescription
    };
    $http.post('/createRoom', newRoom).then(function(){
      $scope.roomName = '';
      $scope.moderator = '';
      $scope.description = '';

      $location.path('/createRoom');

      bootbox.alert('Sucessfully created Room.');
    });
  };


}]);


//server side route
//get rooms 

app.get('/rooms', function(req,res){
  Room.find({}, function (err, rooms) {
        res.send(rooms);
        console.log(rooms);
      });
    });


//relevant part of partial page
    <div class="container-fluid" id="roomsPage" data-ng-init="getRooms()">

检查您的服务器端路由。您正在登录 index.html 页面,因为您的请求没有到达任何快速路线。因此它会点击 app.get(*) 路由并返回 index.html 页面的 html。确保一切都拼写正确并且你在另一端使用 get 而不是 post 除非你想