我在angularjs和nodejs中有Moto Adverts应用程序.Angularjs-client-side在Apache HTTP Server(localhost:8000)上运行,但nodejs-server-side以node.js http server(localhost:3000)运行.
一块客户端代码(angularjs):
var motoAdsServices = angular.module('motoAdsServices', ['ngResource']);
motoAdsServices.factory('Brand', ['$resource', function($resource) {
return $resource('http://localhost\\:3000/api/:id', {}, {
query: {
method: 'GET',
params: {
id: 'brands'
},
isArray: true
}
});
}]);
Run Code Online (Sandbox Code Playgroud)
一块服务器端代码(nodejs):
var express = require('express');
var path = require('path');
var http = require('http');
var brands = require('./routes/brands');
var app = express();
var allowCrossDomain = function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
};
app.configure(function() {
app.set('port', process.env.PORT || 3000);
app.use(express.logger('dev')); /* 'default', 'short', 'tiny', 'dev' …Run Code Online (Sandbox Code Playgroud) 我不明白为什么在Firefox window.history.back()中可以使用按钮:
<button onclick="window.history.back()">Go back</button>
Run Code Online (Sandbox Code Playgroud)
但它不适用于链接:
<a onclick="window.history.back()">Go back</a>
Run Code Online (Sandbox Code Playgroud)
有什么不同?
举例说明:
的index.html
<!DOCTYPE html>
<html>
<body>
<h1>First page</h1>
<br/>
<a href="second.html">Second</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
second.html
<!DOCTYPE html>
<html>
<body>
<h1>Second page</h1>
<a href="third.html">Third</a>
<br/>
<br/>
<button onclick="window.history.back()">Go Back (button)</button>
<br/>
<a href="javascript: void(0);" onclick="window.history.back()">Go Back (a)</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
third.html
<!DOCTYPE html>
<html>
<body>
<h1>Third page</h1>
<br/>
<button onclick="window.history.back()">Go Back (button)</button>
<br/>
<a href="javascript: void(0);" onclick="window.history.back()">Go Back (a)</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
场景:
我有休息服务:
http://localhost:3000/api/brands
Run Code Online (Sandbox Code Playgroud)
当我从网络浏览器测试它时效果很好.
我在角度服务中使用它:
var motoAdsServices = angular.module('motoAdsServices', ['ngResource']);
motoAdsServices.factory('Brand', ['$resource', function($resource) {
return $resource('http://localhost:3000/api/:id', {}, {
query: {
method: 'GET',
params: {
id: 'brands'
},
isArray: true
}
});
}]);
Run Code Online (Sandbox Code Playgroud)
当它被调用时我有错误,因为在reqest URL中我没有端口号:
Request URL: http://localhost/api/brands
Run Code Online (Sandbox Code Playgroud)
为什么端口数字被削减?角切呢?
在Angular doc中写道:
参数化的URL模板,其参数前缀为:in/user /:username.如果您使用的是带有端口号的URL(例如http://example.com:8080/api),则会受到尊重.
UPDATE
我使用角度版本1.0.8(感谢@KayakDave供你注意),但Angular doc适用于版本1.2.