因为在AngularJS中使用CORS和http认证可能很棘手,所以我编辑了这个问题,分享了一个学到的课程.首先,我要感谢igorzg.他的回答对我很有帮助.方案如下:您希望使用AngularJS $ http服务将POST请求发送到其他域.获取AngularJS和服务器设置时需要注意几个棘手的事情.
第一:在您的应用程序配置中,您必须允许跨域调用
/**
* Cors usage example.
* @author Georgi Naumov
* gonaumov@gmail.com for contacts and
* suggestions.
**/
app.config(function($httpProvider) {
//Enable cross domain calls
$httpProvider.defaults.useXDomain = true;
});
Run Code Online (Sandbox Code Playgroud)
第二:您必须指定withCredentials:true并将用户名和密码指定为请求.
/**
* Cors usage example.
* @author Georgi Naumov
* gonaumov@gmail.com for contacts and
* suggestions.
**/
$http({
url: 'url of remote service',
method: "POST",
data: JSON.stringify(requestData),
withCredentials: true,
headers: {
'Authorization': 'Basic bashe64usename:password'
}
});
Run Code Online (Sandbox Code Playgroud)
Тhird:服务器设置.你必须提供:
/**
* Cors usage example.
* @author Georgi Naumov
* gonaumov@gmail.com …Run Code Online (Sandbox Code Playgroud) 我有一个使用firebase存储用户数据的前端角度应用程序.
我目前没有设置后端,例如node.js服务器.
我想使用Google Docs API从我的应用上传文件.
由于中国的防火墙没有(或使其不稳定)使用Google服务,是否可以将这些服务放在后端服务器上并仍然可靠地使用它们?
也许在他们将文档上传到firebase之后,后端脚本会检索它,将其上传到google docs,然后从firebase中删除记录?试着看看谷歌或类似的服务是否适用于这个用例.
我想我的问题的关键在于是否会在用户的计算机上调用Google API,在这种情况下它会变得不稳定吗?
**更新清晰度:
我决定我的firebase支持的应用程序是否需要像节点服务器这样的更传统的后端来执行以下操作:上传图像和文档,通过Mandrill发送邮件等等...如果我知道是否在放入后会对我有所帮助在创建服务器的时候,我所追求的一些服务(也就是API)对于GFW来说比在客户端运行时更具弹性.因此,如果任何人在这项任务中取得成功,我想知道.
**技术更新:
因此,例如,如果我在客户端运行Google Maps API,如果用户在中国并且没有运行VPN,则访问API调用将滞后或超时或(很少)成功返回脚本.如果我能够以某种方式能够在服务器上处理地图查询"off-site",那么我可以将地图的静态图像返回给中国用户吗?
我正在使用angular-ui打开和关闭模态.当我用submit(object)或关闭它时dismiss(message),对话框关闭,但屏幕仍然显示为灰色,我无法访问我的应用程序.一些代码:
父控制器(相关部分):
$scope.deleteConfirm = function(toDelete) {
console.log(toDelete);
var modalObj = {
templateUrl: 'views/templates/delete.html',
controller: 'DeleteCtrl',
size: 'sm',
resolve: {
toDelete: function() {
return toDelete;
},
collection: function() {
return $scope.users;
}
}
}
var modalInstance = $modal.open(modalObj);
modalInstance.result.then(function (deletedItem) {
console.log(deletedItem);
});
Run Code Online (Sandbox Code Playgroud)
};
父html:
<button class="btn btn-danger btn-xs" ng-click="deleteConfirm(user)">X</button>
Run Code Online (Sandbox Code Playgroud)
模态控制器:
.controller('DeleteCtrl', ['$scope', '$modalInstance', 'toDelete', 'collection', function ($scope, $modalInstance, toDelete, collection) {
$scope.toDelete = toDelete;
$scope.remove = function() {
collection.$remove(toDelete).then(function(ref) {
$modalInstance.close(ref);
});
};
$scope.cancel = function …Run Code Online (Sandbox Code Playgroud) 从性能的角度来看,我想知道匹配的模式顺序是否影响函数的效率,或者它更多地与预期的不同匹配的比例有关(即,如果一个模式发生的方式比其他模式更多,它应该更早出现).
(* a function to return the smaller of two int options, or None if both are None. If exactly one argument is None, return the other. *)
let min_option (x: int option) (y: int option) : int option =
match x, y with
None, None -> None
| Some x, None -> Some x
| None, Some y -> Some y
| Some x, Some y -> if x < y then Some x else Some y
let () …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的csv文件:
"a", "b", "c"
"1", "b", "4"
"3", "g", "f"
Run Code Online (Sandbox Code Playgroud)
无论何处"b"出现在与两个连续行中的第二列值相同的位置,我想删除第二行,从而导致:
"a", "b", "c"
"3", "g", "f"
Run Code Online (Sandbox Code Playgroud)
这至少让我开始解析:
awk -F "," '$1' file.csv
Run Code Online (Sandbox Code Playgroud)