1

I have an existing Electron Angular app all running fine. I want to create a new window on a button click and have that window use a given Angular component for it's initial UI content.

So I make a new component like so:

ng generate component TrivialComponent

Now, in my electron app I make sure that at top of app.module.ts I have:

import { TrivialComponent } from './trivial.component';

and also that it is added to declarations like so:

@NgModule({
  declarations: [
    AppComponent,
    TrivialComponent,

now, on my button click event I add:

var w = new BrowserWindow({
                title: "My Title",
                minWidth: 800,
                minHeight: 600,
                frame: true,
                resizable: true,
                transparent: false,
                closable: true,
                show: false,
                webPreferences: {
                  nodeIntegration: true,
                  contextIsolation: false,
                  allowRunningInsecureContent: true,
                  enableRemoteModule: true
                } as Electron.WebPreferences
              });

              w.show();

                w.loadFile("dist/index2.html");

and the body of index2.html is:

<body class="igx-typography">
  <app-trivial></app-trivial>
</body>

When I run this I get a new empty window, but content is blank rather then the html of my new component, which is:

<p>Trivial component works!</p>

Would anyone know what I am missing?

1 Answer 1

0

You can try to create standard routing to new component and then try this before showing:

w.once('ready-to-show', () => {
            if (urlToOpen) {
                win.webContents.send('openUrl', urlToOpen);
                if (win.isMinimized()) win.restore()
                win.focus()
            }
        });

where urlToOpen is the URL with the route to the component. But to be precise we use this solution when a user opens the electron app from the browser by navigating to: ourapp://urlToOpen. I don't remember right now how does the urlToOpen looks like inside the code. does it have the ourapp prefix or not. If it has navigating in that way might be a workaround.

Not the answer you're looking for? Browse other questions tagged or ask your own question.