【问题标题】:Is there a way to create a modeless dialog in an Angular/Electron app?有没有办法在 Angular/Electron 应用程序中创建无模式对话框?
【发布时间】:2020-05-11 07:23:00
【问题描述】:

有没有办法在 Angular/Electron 应用程序中创建无模式对话框?

我正在查看下面的示例,它们都是模态的:

https://material.angular.io/components/dialog/overview

我需要能够同时打开多个窗口并四处移动它们。但我找不到任何样本。

谢谢。


编辑 1:

我尝试了以下方法,但不知何故将我引导至默认页面 index.html:

window.open('/app/shared/settings/user-preferences.html'); 

编辑 2:

我也尝试了以下方法,但无法编译。

const { BrowserWindow } = require('electron'); //does not compile!!?
let win = new BrowserWindow({ width: 800, height: 600 });
win.on('closed', () => {
  win = null;
});

win.loadURL(`file://${__dirname}/app/shared/settings/user-preferences.html`);

但这不会编译并给我错误消息:

ERROR in ./node_modules/electron/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\projects\...\MyApp\node_modules\electron'
ERROR in ./node_modules/electron/index.js
Module not found: Error: Can't resolve 'path' in 'C:\projects\...\MyApp\node_modules\electron'

【问题讨论】:

  • 嗨,你的意思是 window.open() 之类的?就像在带有对话框上下文的实际新窗口中一样...
  • 感谢您的回复。 window.open() 可能会。我已经尝试过了,但它以某种方式导致 Index.html。我是否正确使用它? window.open('/app/shared/settings/user-preferences.html');
  • 检查帖子是否是您要查找的内容

标签: angular angular-material dialog electron modeless-dialog


【解决方案1】:

您可以使用window.open() API 通过提供这样的 URL 并在其中使用对话框上下文来打开窗口的新窗口实例:

window.open('https://www.angular.io', 'nameOfWindow');

这是一个有效的example

EDIT1:

考虑到electron API 设置,您还需要执行以下操作:

如果您想使用 Chrome 的内置 window.open() 实现,请在 webPreferences 选项对象中将 nativeWindowOpen 设置为 true。

EDIT2:

考虑到本地文件,您可以这样做:

window.open(`file://${__dirname}/app/shared/settings/user-preferences.html`, 'nameOfWindow')

【讨论】:

  • 感谢您的回复。不幸的是,这不是我所追求的。我正在为桌面运行 Electron 应用程序,而不是网站。所以我需要一种打开本地文件的方法,类似于:window.open('/app/shared/settings/user-preferences.html');
  • 感谢您的建议。它仍然不起作用。它打开一个空白的 HTML 屏幕,头部空白,正文空白。我也尝试将文件重命名为 index.html,但还是不行。
  • 您是否记录了 EDIT2 的文件路径并将其与它的实际位置进行比较,因为它可能是路径问题?
  • 很确定我做到了。虽然我不完全确定这与 {__direname} 路径有何关系。我试过另一个文件位于: C:\Projects\TestApp\src\components\share\share-file-dialog\share-file-dialog.component.html ...我到目前为止得到的代码是:window .open(file://${__dirname}/src/components/share/share-file-dialog/share-file-dialog.component.html, 'TestSettings123');
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-07-05
  • 2019-06-19
  • 2021-03-07
  • 1970-01-01
  • 1970-01-01
  • 2022-01-20
  • 1970-01-01
相关资源
最近更新 更多