AngularJS:将数据传递到Internet Explorer上的新浏览器窗口时出现问题 [英] AngularJS : Issue passing data to a new browser window on Internet Explorer

查看:222
本文介绍了AngularJS:将数据传递到Internet Explorer上的新浏览器窗口时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一些对象传递到新的浏览器窗口.我遵循了 AngularJS的建议:打开一个新的浏览器窗口,但仍保留作用域和控制器以及服务

I am trying to pass some objects to a new browser window. I followed the suggestion from AngularJS: open a new browser window, yet still retain scope and controller, and services

它可以在Chrome上运行,但不能在IE上运行.我的共享对象在IE上总是 undefined .有什么建议吗?

It works on Chrome, but doesn't on IE. My shared objects are always undefined on IE. Any suggestions?

我尝试做的简化版本的代码

Code for simplified version of what I am trying to do

我的父母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);

推荐答案

根据shaunhusain和Sunil D的建议,我将代码更改如下,并且可以正常工作

Per shaunhusain and Sunil D's suggestions, I have changed my code as below and it works

我的父母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);

};

这篇关于AngularJS:将数据传递到Internet Explorer上的新浏览器窗口时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆