【发布时间】:2018-01-02 21:44:42
【问题描述】:
在这个页面上搜索了很久,我还是迷路了。
我有一个 AppModule 和一个 ModalModule。 AppModule 正在导入 ModalModule
AppModule 使用此装饰器属性声明 LoaderComponent:
selector: 'my-loader', template: '<div>...</div><ng-content></ng-content>'
ModalModule 声明 ModalComponent。
在 ModalComponent 的模板里面我要使用 LoaderComponent:
<my-loader><h3>Loading...</h3><p>Just information text.</p></my-loader>
这不起作用!
'my-loader' is not a known element:
1. If 'my-loader' is an Angular component, then verify that it is part of this module.
2. If 'my-loader' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
如果我将 CUSTOM_ELEMENTS_SCHEMA 添加到 ModalModule,它只会忽略元素并且 DOM 看起来像这样:
<my-loader>
<h3>Loading...</h3>
<p>Just information text.</p>
</my-loader>
但我希望它通过 angular 渲染,看起来像这样:
<my-loader>
<div>...</div> <!-- should be coming from LoaderComponent template -->
<h3>Loading...</h3>
<p>Just information text.</p>
</my-loader>
有人有想法吗?
【问题讨论】:
-
在我的帖子之后,我发现了这个并会尝试一下:stackoverflow.com/questions/39906949/…
标签: angular components ng-modules