AngularJS 애플리케이션 (주)에는 내 제어하에 또 다른 AngularJS 애플리케이션 (iframe)이있는 iframe
이 있습니다. 주 응용 프로그램과 iframe 응용 프로그램에서 두 가지 서비스간에 데이터를 공유하고 싶습니다. 그들은 모두 동일한 객체를 읽고 쓸 필요가 있습니다.다른 프레임 내의 서비스에서 AngularJS 서비스에 액세스
var self = this;
var parentScope = $window.parent.angular.element($window.frameElement).scope();
parentScope.$watch('serviceA.sharedData', function (newValue, oldValue) {
self.sharedData = newValue;
}
이 달성 할 수있는 방법 :
// main
// ... routes ...
views: { main: {
controller: function ($scope, serviceA) {
$scope.serviceA = serviceA;
},
templateUrl: 'iframe.html'
}
// ...
function ServiceA() {
this.sharedData; // exposed to controllers in main app
}
// ...
// iframe
// ...
function ServiceB() {
this.sharedData; // exposed to controllers in iframe app
}
// ...
언제 iframe이 응용 프로그램의 컨트롤러 내에서이 같은
serviceA.sharedData
를 참조하는 관리?
나는 다음을 읽고, 아직, 솔루션으로 바꿀 수 없습니다 :
당신이 언급 한 두 번째 질문에 대한 대답은 당신이 theIFrameElement'와 iframe이의 각 개체에 액세스 할 수 있다고 말한다 .contentWindow.angular'. 그게 너에게 효과가 있니? – user1950929
예, 이와 같이 'angular'객체에 액세스 할 수 있습니다. 그런데 어떻게 등록 된 서비스에 액세스 할 수 있습니까? – hielsnoppe
서비스를 컨트롤러의 범위에 추가하면 외부 (즉, 상위 프레임)에서 액세스 할 수 있습니다. – user1950929