Electron Forge + Angular 4打破''anonymous'并不是一个已知的元素

时间:2017-07-25 09:45:54

标签: angular electron electron-forge

我使用angular2模板重新安装了Electron Forge。我将Angular依赖项追溯到^4.3.1zone.js^0.8.14并将hammerjs添加到package.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组件和*ngIf上的app-search-view组件。我过去常常使用moduleId : module.id.split('\\').join('/'),添加@Component声明,但这不起作用。

我真的被困在这里。

有什么想法吗? 谢谢!

修改

以下是media中<{1}}的定义方式:

app-media-view

以下是get media(): Media { return this._media; } @Input() set media(value: Media) { this._media = value; // More things }

appState的定义方式
AppComponent

2 个答案:

答案 0 :(得分:1)

您的组件app-search-view或app-media-view可能存在一些错误的引用。

您是否在@Input() media: any;组件中声明了app-media-view

您的app-component中是否声明了appState?也许你可以尝试打印它们并查看。

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

答案 1 :(得分:0)

在组件定义中

添加“ moduleId:module.id.split('\')。join('/'),”可以达到目的:

@Component({
  moduleId : module.id.split('\\').join('/'), 
  selector: 'App',
  templateUrl:'./app.component.html'
})
export class AppComponent implements OnInit {//...}
相关问题