I am starting using AngularJS, and setup a server with nodejs, everything goes great, but when i open chrome developers tools i see that the app make two ajax repeat calls for get the json data that node/mongo send. first i think that the template jade was the problem, but after use plain html, works in the same way
any idea?
here is the code in AngularJS
angular
.module('foro')
.config(function($routeProvider){
$routeProvider
.when("/",{
templateUrl : "/partials/questions.html",
controller: "QuestionsCtrl"
})
.when("/questions/:questionId",{
templateUrl: "/partials/singleQuestion.html",
controller: "SingleQuestion"
})
})
.controller("QuestionsCtrl", function($scope, $http){
$http.get("/questions").success(function(data){
$scope.questions = data;
});
})
.controller("SingleQuestion", function($scope, $http, $routeParams){
var questionId = $routeParams.questionId;
$http.get("/question/"+questionId).success(function(data){
$scope.question = data;
$scope.votes = data[0].votes;
});
this is how respond in node/express server
app.get('/questions', function (req, res) {
Question.find({}).sort({_id:"descending"}).execFind(function(err,docs){
if(err) res.json(err)
res.json(docs)
});
});
app.get('/question/:questionId', function (req, res) {
var questionId = req.params.questionId;
Question.find({_id: questionId},function(err,docs){
if(err) res.json(err)
res.json(docs)
});
});