我想动态创建一个头,构造并将头模板作为'字符串'传递给我的动态组件。我的要求是调用头组件模板字符串中的另一个组件并加载它。Angular 2 - 获取子组件加载父组件(动态创建)
已经创建了一个工作Plunker这里的场景。
我得到一个错误,在浏览器控制台为:
Unhandled Promise rejection: Template parse errors:
'alert' is not a known element:
1. If 'alert' is an Angular component, then verify that it is part of this module.
2. If 'alert' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. (" <span class="title" style="float: right; margin-right: 10px;">
[ERROR ->]<alert></alert>
<img class="notify-circle" src="https://cdn0.iconf"): [email protected]:32 ; Zone: <root> ; Task: Promise.then ; Value: Object { _nativeError: Error, stack: "" } [email protected]://unpkg.com/@angular/compiler/bundles/compiler.umd.js:1595:29 [angular]
问:
我怎样才能构建为一个字符串的头部模板内公认的“警报”组件,使用选择器'<alert></alert>'
。
这个概念可能看起来怪异,但要求是这样的。
@ yurzui ..感谢..我的要求完美..将帮助我的很多类似的情况。你可以发布你的答案接受。 – Ranjan