As I attempt to dynamically insert a BlockComponent
into a GridLayoutComponent
, an error is thrown:
Uncaught Error: Can't resolve all parameters for BlockComponent: (?, [object Object])
. This issue arises upon page load and stems from the addBlock
function in the GridLayoutComponent
. My knowledge of dynamically adding components in Angular is limited, and the tutorials I've come across have been overly simplistic, lacking detailed instructions on dealing with constructors. Below is my code snippet:
grid-layout.component.ts:
// Code here
block.components.ts:
// Code here
I've noticed that the grid
attribute of the GridLayoutComponent
does not possess a createComponent
method. Could someone enlighten me on the correct way to dynamically create a component in Angular and append it to the page?
EDIT:
Pre-existing BlockComponent
s function without any issues.
grid-layout.component.html:
// HTML code here
EDIT 2:
My code can be found on GitHub (link) and accessed on StackBlitz (link)
EDIT 3:
I have removed the @Host
parameter to access the GridLayoutComponent
from within the BlockComponent
, retrieving it instead from the EditGridService
. While this workaround functions, I suspect there must be a more appropriate solution to managing a component factory with a @Host
parameter.