首页 > 解决方案 > Index.html 未链接到电子角度中的 app.component

问题描述

我正在尝试将电子添加到现有的角度项目中。

我像新应用程序一样添加,我认为我配置正确但是当我运行我的电子应用程序时,屏幕上什么都没有显示。

这是 main.js,我如何加载电子应用程序的 index.html。

function createWindow () {
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true
    }
  })

  win.loadFile('./src/index.html')      
  win.setMenu(null);
}

索引.html=>

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Testing</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- <link rel="icon" type="image/x-icon" href="favicon.ico"> -->
</head>
<body>
  <app-root></app-root>
</body>
</html>

app.component.html

<h1 class="app-root">Welcome to sub-app1!</h1>
<router-outlet></router-outlet>

这是 app-router.component.ts

const routes: Routes = [
  {
    path: '',
    redirectTo: 'test',
    pathMatch: 'full'
  },
  {
    path: 'test',
    component: TestComponent
  }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

我在 app.component.ts 的构造函数中添加了一个控制台,但没有打印。

当我运行这个电子子应用程序时,屏幕上什么也没有显示。看起来像 index 和 app.component.ts,而不是链接。

我错过了什么?

标签: angularelectronangular10

解决方案


按照这个存储库。它将帮助您使用开发环境和生产环境设置角度。


推荐阅读