Ich würde verwenden betrachten postMessage mit ...
In Angular Bedingungen würde dies bedeuten, dass ein App-Nachrichten senden würde und die andere, um Nachrichten zuhören würde.
Also auf der App, die innerhalb des iframe sitzt können Sie eine Fabrik machen, die die folgenden:
/**
* App that sits within iframe:
*
* Inject this factory into your controller and call
* iFrame.messageParentIframe({hello: 'world'}) to send messages
* to the parent iFrame
*/
angular
.module('app')
.factory('iFrameMessenger', function($window) {
return {
messageParentIframe: function(message) {
$window.parent.postMessage(message, '*');
}
};
});
auf der übergeordneten iFrame Code sollte wie folgt aussehen:
/**
* App that is on parent iframe:
*
* Just using a controller for the sake of simplicity,
* but you could also use a Factory that only receives
* messages from iFrames and handle them according to each
* action, etc. You can get creative here on how you want
* to handle it.
*/
angular
.module('app')
.controller('AppCtrl', function($window) {
$window.addEventListener('message', function() {
// handle messages received from iframe
});
});
warum Sie Rendern diese beiden App in zwei verschiedenen iframe? Was wirst du damit erreichen? –