AngularJS在用户点击范围内等待$resource承诺
AngularJS Waiting for $resource Promise in the Scope of a User Click
我是前端/AngularJS开发的新手,并且已经阅读(但不完全理解)许多堆栈溢出问题和其他有关ng-resource/$resource和承诺的文档。我的情况有点奇怪。
我在提交函数中有此代码,当用户单击按钮提交表单时。
var Resource = $resource("/urlHere",{},{save: {method:'POST', isArray:true}});
Resource.save(JSON.stringify($scope.validQuery)).$promise.then(function(data) {
$scope.initialResults=data;
if($scope.initialResults.length === 0){
alert("No Results Found!");
}else if($scope.initialResults.length === 1){
window.data = $scope.initialResults;
window.open('/detailedResults');
}else if($scope.initialResults.length > 1){
window.data = $scope.initialResults;
var popupWindowResults = window.open('/resultsGrid');
}
});
我需要打开某个选项卡,具体取决于我得到的结果数量。(基本上显示一个有多个结果可供选择的网格,或者如果只返回 1,则只显示单个结果)当 window.open 不包含在 $promise.then 中时,它可以正常工作。在 $promise.then 中,浏览器将其视为弹出窗口,而不是用户单击某些内容后的新选项卡。
有没有办法在返回结果之前停止执行,以便我可以在 $promise.then 之外和提交函数中打开一个选项卡?任何解决方案都将非常有帮助。
http://jsfiddle.net/az066xcs/2/
$scope.getResults = function() {
var win = window.open();
// this is a placeholder for the async call that gets results
setTimeout(function() {
win.document.write('<h1>Results Loaded!</h1>');
}, 1000);
};
您可以在单击时打开窗口,然后异步加载结果并将其插入新窗口中。显然,比带有document.write
的空白窗口更好的解决方案是在新窗口中放置另一个角度应用程序,或者至少是一个简单的javascript应用程序。
相关文章:
- 单击按钮以等待单击按钮
- React组件等待所需道具进行渲染
- 正在等待呈现图表,直到加载数据为止
- 在等待ajax请求时显示微调器并禁用页面
- Javascript在for循环中等待处理请求
- JavaScript循环并等待函数
- 在等待异步任务时永久循环
- 在通过child.print()打印之前,我如何等待图像加载到我的新窗口中
- 失败:等待Protractor与页面同步时出错:“”;在窗口上找不到角度”;
- 等待300毫秒,然后使用jQuery向下滑动菜单
- 可以't通过Angular$resource POST数据
- 等待循环调用的所有承诺完成
- 等待回调函数执行
- RxJS等待承诺解决
- AngularJS在.run中等待Resource
- 使用$resource时,量角器等待与页面同步超时
- $save().then 在 Angular 上$resource不等待服务响应
- 在服务中等待 Angular JS(REST -> $resource)
- AngularJS在用户点击范围内等待$resource承诺
- AngularJS等待$resource响应来设置值