Recently, I attempted to utilize ComponentFactoryResolver in order to generate dynamic Angular components. Below is the code snippet where I am injecting ComponentFactoryResolver.
import { Component, ComponentFactoryResolver, OnInit, ViewChild } from "@angular/core";
@Component({
selector: "app-component",
template: `
<h1>{{title}}</h1>
`
})
export default class AppComponent implements OnInit {
private title = "Hello World";
constructor(private componentFactoryResolver: ComponentFactoryResolver){
}
ngOnInit() {}
}
However, upon running the application, an exception was thrown in the browser console displaying the following error message:
Error: Can't resolve all parameters for AppComponent: (?).
In my project's dependency (package.json), I have specified the dependencies and devDependencies used for webpack compilation.
{
"name": "angular_hello_world_example",
"version": "1.0.0",
...
Furthermore, here is some additional information regarding the module declaration:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { NgModule } from '@angular/core';
...