您在NodeJS中設置的路由需要通過$ http角度來訪問。應使用ng-route在前端應用程序中處理URL路由。
如果你想通過服務器在角度的$範圍內呈現你的頁面,你將不得不讓服務器生成角碼來做到這一點......但這只是過於複雜的事情。最好讓有角度的手柄檢索這些數據。
使用的angularjs服務:
angular.module('yourApp')
.service('pageLoader', function($http) {
var baseUrl = ''; // this will be the url for your server. Normally
// 'localhost' or something similar if it is a test
// environment
return this.loadPage = function() {
return $http.get(baseUrl + '/page');
}
})
.controller('PageCtrl', function($scope, pageLoader) {
$scope.page = null;
$scope.loadPage = function() {
pageLoader.loadPage().then(function(data) {
$scope.page = data;
})
}
});
這只是給你如何做到這一點的想法。如果您執行搜索,則有許多不同的$ http服務示例。
在您的nodejs中將'render'改爲'send'。
編輯:我假設你正在使用角度前端應用程序,而不是某種其他模板系統。您應該發送該信息並使用angular來生成包含該信息的頁面。
你如何在前端製作req-res?你使用$ http? –
@Shimbr我不知道。這個GET請求是當有人點擊一個鏈接時。 –