1

我有一个页面addin.html。它可以通过异步通信交叉页面

popup = window.open("https://localhost:3000/#/posts/editor/", "popup") 

弹出另一个页面editor(这不一定在同一个域)然后,两页有每个一个监听器里,并可以通过

// listen: 
function receiveMessage(event) { 
    document.getElementById("display").innerHTML = JSON.stringify(event.data); 
} 
window.addEventListener("message", receiveMessage, false); 

// send: 
function sendMessage() { 
    popup.postMessage("data", popup.location.href); 
} 
将数据发送到对方

editorui-router实现。

.state('editor', { 
    controller: 'EditorCtrl', 
    resolve: { init: [ ... ] }, 
    ... 
}; 

app.controller('EditorCtrl', ['$scope', 'init', function ($scope, init) { 
    ... 
}] 

我想现在落实就是addin.html弹出窗口editor,它会发送一些数据editor,并init需要解决这一数据,加载页面的:首先,它加载页面的解析initeditor在收到来自addin.html的数据之前可能会挂起。

有谁知道如何修改接收器和发送器(和别的东西)来做到这一点?

+0

难道你不能通过URL参数传递这个初始数据吗? –

+0

可能有很多数据,我怎么把它们嵌入'window.open'? – SoftTimur

+0

没有太多的选择。如果数据太大,请使用服务器端会话来存储和检索数据。或使用POST发送数据。 – estus

回答

0

你可以返回一个自定义的承诺,只要你想为下面的代码

.state('editor', { 
    controller: 'EditorCtrl', 
    resolve:{ 
    init: function($q){ 
     var deferred = $q.defer(); 
     window.addEventListener("message", function(event){ 
       deferred.resolve(event.data); 
     }, false); 
     return deferred.promise; 
    } 
    } 
}); 

控制器等待上述项目实例之前得到彻底解决解决。

+0

谢谢......我还没有测试过......所以在视觉上,用户在解决之前会看到什么?空白页面? – SoftTimur

+1

嗨,是用户界面视图将是解决http://stackoverflow.com/questions/18961332/angular-ui-router-show-loading-animation-during-resolve-process – fingerpich

+0

我的测试表明它的工作原理之前,空.. 。 – SoftTimur