我正在学习并尝试使用Node和Express连接AngularJS。但是当我请求'/'路径时,我收到了这个错误:
Error: Access to restricted URI denied
createHttpBackend/<@file:///D:/Mean/routing/js/angular.js:9902:6
sendReq@file:///D:/Mean/routing/js/angular.js:9703:0
$http/serverRequest@file:///D:/Mean/routing/js/angular.js:9415:15
processQueue@file:///D:/Mean/routing/js/angular.js:13292:26
scheduleProcessQueue/<@file:///D:/Mean/routing/js/angular.js:13308:26
$RootScopeProvider/this.$get</Scope.prototype.$eval@file:///D:/Mean/routing/js/angular.js:14547:15
$RootScopeProvider/this.$get</Scope.prototype.$digest@file:///D:/Mean/routing/js/angular.js:14363:14
$RootScopeProvider/this.$get</Scope.prototype.$apply@file:///D:/Mean/routing/js/angular.js:14652:12
done@file:///D:/Mean/routing/js/angular.js:9734:35
completeRequest@file:///D:/Mean/routing/js/angular.js:9924:6
requestLoaded@file:///D:/Mean/routing/js/angular.js:9865:0
在控制台中,我也看不到路径的任何命中。但是当我在浏览器中运行localhost:3000时,它会命中。
这是我的角度控制器:
app.controller('MainCtrl', function($scope, $http) {
$http({
method: 'GET',
url: '/'
}).
success(function(data, status, headers, config) {
$scope.name = data.name;
}).
error(function(data, status, headers, config) {
$scope.name = 'Error!';
})
})
我的服务器:
var express = require('express'),
http = require('http');
var app = express();
app.set('port', 3000);
app.get('/', function(req, res) {
var name = 'NameFromWeb';
res.send(name);
})
http.createServer(app).listen(app.get('port'), function () {
console.log('Express server listening on port ' + app.get('port'));
});
我知道这与直接运行index.html文件有关,而不是与服务器有关。但我对此并不清楚。