2

我已经用angular2模板重新安装了 Electron Forge。我将 Angular 依赖项添加到^4.3.1zone.jsto^0.8.14并添加hammerjspackage.json(以使用 Angular 4 材质组件)。

src/app然后我在目录中添加了一个功能性 NG4 应用程序的源代码。

运行electron-forge start控制台输出正确且应用程序启动时,但 DevTools 显示此错误:

Unhandled Promise rejection: Template parse errors:
'anonymous' is not a known element:
1. If 'anonymous' is an Angular component, then verify that it is part of this module.
2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("tin\Desktop\ef-ng\node_modules\electron-compile\lib\protocol-hook.js:216:25)
    at Generator.next ([ERROR ->]<anonymous>)
    at step (C:\Users\Quentin\Desktop\ef-ng\node_modules\electron-compile\lib\protocol-h"): ng:///C:/Users/Quentin/Desktop/ef-ng/src/app/app.component.html@4:23

这是我的app.component.html样子:

<app-main-toolbar></app-main-toolbar>
<app-tree-item-tabs></app-tree-item-tabs>
<app-search-view *ngIf="appState.searchIsVisible"></app-search-view>
<app-media-view *ngIf="appState.activeMedia" [media]="appState.activeMedia"></app-media-view>

如果我用它替换它,那么它运行正常(但当然这不是我想要的):

<app-main-toolbar></app-main-toolbar>
<app-tree-item-tabs></app-tree-item-tabs>
<app-search-view></app-search-view>

请注意,我删除了组件app-media-view和一个。我曾经使用一个技巧添加到我的声明中,但这在这里不起作用。*ngIfapp-search-viewmoduleId : module.id.split('\\').join('/'),@Component

我真的被困在这里了。

任何想法?谢谢!

编辑

以下media是在 中定义的方式app-media-view

get media(): Media {
    return this._media;
}

@Input()
set media(value: Media) {
    this._media = value;
    // More things
}

以下appState 是在 中定义的方式AppComponent

constructor(
    protected bootstrap:BootstrapService,
    public appState: AppStateService) {}
4

2 回答 2

1

您的组件 app-search-view 或 app-media-view 中可能有一些不好的参考。

@Input() media: any;在你的app-media-view组件中声明了吗?

是否appState在您的应用程序组件中声明?也许您可以尝试打印它们并查看。

如果您在 src/app 目录中添加了功能性 NG4 应用程序(不是 electron-forge)的源代码,则需要更改对模板和样式的所有导入和引用。 app不再是您的根文件夹。现在根文件夹是src. 因此,例如,如果您必须templateUrl: ./myTemplate.html更改为templateUrl: ./src/app/myTemplate.html.

于 2017-08-22T21:53:30.247 回答
0

在组件定义中添加 "moduleId : module.id.split('\').join('/')," 就可以了:

@Component({
  moduleId : module.id.split('\\').join('/'), 
  selector: 'App',
  templateUrl:'./app.component.html'
})
export class AppComponent implements OnInit {//...}
于 2018-10-03T15:59:36.930 回答