I am trying to dynamically render a string containing HTML markup in Angular. The HTML should be 'Angular compiled', i.e. including data binding and rendering of components (the sort of things I did with $compile
in AngularJS).
I have the most part of it working using p3x-angular-compile:
<div [p3x-compile]="Template.Source" [p3x-compile-ctx]="Data"></div>
works as expected and correctly renders Template.Source
, i.e.:
this.Template.Source = '<p>Hello</p>';
and also
this.Template.Source = '<p>{{Foo}}</p>';
where Foo is a property on the bound Data
object.
However, rendering my self defined angular components doesn't work:
this.Template.Source = '<app-sc-navbar></app-sc-navbar><p>Other arbitrary markup anywhere in string'</p>;
yields an error:
CompileAttribute.js:80
Error: Template parse errors: 'app-sc-navbar' is not a known element: 1. If 'app-sc-navbar' is an Angular component, then verify that it is part of this module. 2. If 'app-sc-navbar' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
The component (ScNavbarComponent
) is part of the declarations of the app module, and - if used in static markup - works fine.
What am I missing here? How can I make the dynamic rendering aware of ScNavbarComponent
?
EDIT:
This is the full debugger output:
I have tried adding ScNavbarComponent
to exports and/or entryComponents.
@NgModule({
declarations: [
AppComponent,
ScNavbarComponent,
...
],
imports: [
BrowserModule,
...
CompileModule
],
entryComponents: [
ScNavbarComponent
],
providers: [],
bootstrap: [AppComponent],
exports: [
ScNavbarComponent
],
})
export class AppModule { }