angularjs - GET request format using mongoose and angular -
in regard getrooms function, expected console.log, on partial page load (/rooms) , array of objects containing roomname, moderator, , description outlined mongoose model (room) , data in db, render of information page. instead console logging appears index.html code response on client side , server never reached. post , put requests working, , although rudimentary, seems not understanding how go making request. if inform me how done properly, appreciate it.
//roomcontroller.js angular.module('chatapp').controller('roomcontroller', ['$scope','$http','$location', '$cookies', function($scope, $http, $location, $cookies){ // $scope.rooms = [ // {'name': 'biology', 'description': 'discuss wonders of bio'}, // {'name': 'literature', 'description': 'from steinbeck shakespeare'}, // {'name': 'dark souls 3', 'description': 'discuss gameplay ds3'}, // {'name': 'the life of pablo', 'description': "discuss kanye west\'s life of pablo"}, // {'name': 'daredevil', 'description': 'discuss 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()">
check serverside routes. youre logging index.html page because request isnt hitting express routes. instead hits app.get(*) route , returning html of index.html page. make sure spelled right , youre using on other end instead of post unless mean to
Comments
Post a Comment