0
我開始使用AngularJS,並設置一個服務器與nodejs,一切都很好,但是當我打開鉻開發人員工具,我看到該應用程序使兩個Ajax重複調用獲取JSON節點/ mongo發送的數據。 首先我認爲模板玉是問題,但在使用普通的HTML,以同樣的方式在節點快速js重複ajax調用在AngularJS
任何想法的作品?
這裏是AngularJS
angular
.module('foro')
.config(function($routeProvider){
$routeProvider
.when("/",{
templateUrl : "/partials/questions.html",
controller: "QuestionsCtrl"
})
.when("https://stackoverflow.com/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;
});
這是怎麼在節點/ Express服務器
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)
});
});
非常感謝finishingmove問題解決取出NG控制器的一部分! –
沒問題@JoseSosa – finishingmove