मैं postMessage उपयोग करने पर विचार का प्रयोग करेंगे ...
कोणीय संदर्भ में इसका मतलब यह होगा कि एक अनुप्रयोग संदेश और अन्य एक संदेशों को सुनने की जाएगी भेजना होगा।
अनुप्रयोग है कि iframe के भीतर बैठता है आप एक कारखाने जो निम्न करता है बना सकते हैं पर
तो:
/**
* 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, '*');
}
};
});
माता पिता iFrame पर अपने कोड कुछ इस तरह दिखना चाहिए:
/**
* 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
});
});
तुम क्यों इन दो ऐप को दो अलग-अलग आईफ्रेम में प्रस्तुत कर रहे हैं? ऐसा करने से आप क्या हासिल करने जा रहे हैं? –