AngularJS:将数据传递到Internet Explorer上的新浏览器窗口

时间:2014-04-07 19:24:52

标签: angularjs

我正在尝试将一些对象传递给新的浏览器窗口。我遵循了AngularJS: open a new browser window, yet still retain scope and controller, and services

的建议

适用于Chrome,但不适用于IE。我的共享对象在IE上始终是 undefined 。有什么建议吗?

我正在尝试做的简化版的代码

我的父母html

<html ng-app="SampleAngularApp">   

<body>
 <div ng-controller="popupCtrl">
        <my-popup foo="foo" abc="abc">Open Popup from here</my-popup>
    </div>
</body>
</html>

我的父母JS

var SampleAngularApp = angular.module('SampleAngularApp', []);

    var popupCtrl = function ($scope) {

        $scope.foo = { baz: 'qux' };
        $scope.abc = "12345";
    };

SampleAngularApp.directive('myPopup', ['$window', function ($window) {
    return {
        restrict: 'EA',
        scope: {
            foo: '=',
            abc: '='
        },
        link: function (scope, elem, attrs) {
            elem.css({ 'cursor': 'pointer' });
            elem.bind('click', function () {

            var popWdw = $window.open("popupWindow.html", "popupWindow", "width=500,height=500,left=100,top=100,location=no");

            popWdw.abc = scope.abc;
            popWdw.foo = JSON.stringify(scope.foo);

            });
        }
    };
}]);

我的弹出式HTML

<html ng-app="PopupApp">

<body ng-controller="childCtrl">

</body>
</html>

我的弹出式JS

var PopupApp = angular.module('PopupApp', []);

var childCtrl = function ($scope) {   

    alert(window.foo);

};

PopupApp.controller(childCtrl);

1 个答案:

答案 0 :(得分:4)

根据shaunhusain和Sunil D的建议,我已将我的代码更改为如下所示

我的父母JS

link: function (scope, elem, attrs) {
            elem.css({ 'cursor': 'pointer' });
            elem.bind('click', function () {

            $window.abc = scope.abc;
            $window.foo = JSON.stringify(scope.foo);

            var popWdw = $window.open("popupWindow.html", "popupWindow", "width=500,height=500,left=100,top=100,location=no");            

            });
        }

我的弹出式JS

var childCtrl = function ($scope) {   

    alert(window.opener.foo);

};