如何将$ scope变量从窗口发送到父窗口

时间:2017-11-09 15:41:50

标签: javascript angularjs

我正在尝试以角度编写此代码:

{prop: string}

我如何在Angular中编写这行代码? 子元素是以角度编写的,但父窗口的代码是简单的javascript代码。 这行代码在子窗口上执行。

1 个答案:

答案 0 :(得分:0)

postMessage API用于传输字符串而不是对象,因此您应该对其进行序列化。

你可以这样做:

opener.window.postMessage(JSON.stringify({code:$scope.variable1,amount:$scope.variable2}), "*");