如何使用angularJS将数据从主窗口传递到chrome应用程序中新创建的窗口?

时间:2021-07-10 15:12:42

I am currently creating a chrome app just for fun and learning, and then I encountered a problem. From the main window, I created a window that will display your conversation with the name you clicked, but I dont know how to pass data to that new window. Is it possible? if then, how? Here is the code i have.

我目前正在创建一个Chrome应用程序,仅仅是为了娱乐和学习,然后我遇到了一个问题。在主窗口中,我创建了一个窗口,它将使用您单击的名称显示您的对话,但我不知道如何将数据传递到该新窗口。可能吗?如果那么,怎么样?这是我的代码。

    chrome.app.window.create('views/templates/chatWindow.html', {
        'bounds': {
            'width': window.screen.availWidth,
            'height': window.screen.availWidth
        },
        state: 'maximized',
        resizable: false
    });

Please note that I am using AngularJS and I'm working on a windows machine.

请注意我使用的是AngularJS,我正在使用Windows机器。

Also, i have another question. That new window has its own controller, then, how do I get that passed data?

另外,我有另一个问题。那个新窗口有自己的控制器,然后,我如何获得传递的数据?

1 个解决方案

#1


2  

Option 1

A callback function for chrome.app.window.create gives you AppWindow object in return. This object have contentWindow property which is a window object in the newly created window. Having this reference you can fire a custom event on document.body object and handle it in your controller.

chrome.app.window.create的回调函数为您提供AppWindow对象。该对象具有contentWindow属性,该属性是新创建的窗口中的窗口对象。有了这个引用,您可以在document.body对象上触发自定义事件并在控制器中处理它。

Option 2

Use angular's NgRoute and URL's hash to pass data. For example you can do something like:

使用angular的NgRoute和URL的哈希来传递数据。例如,您可以执行以下操作:

chrome.app.window.create('views/templates/chatWindow.html#/client/1234' //...

Then use router and the same app's code to handle view and action.

然后使用路由器和相同的应用程序代码来处理视图和操作。

#1


2  

Option 1

A callback function for chrome.app.window.create gives you AppWindow object in return. This object have contentWindow property which is a window object in the newly created window. Having this reference you can fire a custom event on document.body object and handle it in your controller.

chrome.app.window.create的回调函数为您提供AppWindow对象。该对象具有contentWindow属性,该属性是新创建的窗口中的窗口对象。有了这个引用,您可以在document.body对象上触发自定义事件并在控制器中处理它。

Option 2

Use angular's NgRoute and URL's hash to pass data. For example you can do something like:

使用angular的NgRoute和URL的哈希来传递数据。例如,您可以执行以下操作:

chrome.app.window.create('views/templates/chatWindow.html#/client/1234' //...

Then use router and the same app's code to handle view and action.

然后使用路由器和相同的应用程序代码来处理视图和操作。