background
When practicing routing component lazy loading, set the component to standalone
, and then use *ngModel
in the corresponding html of the component to report an error: a>
Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’.
I searched for many solutions, but they were all solved by directly importing the module FormsModule
.
digression
At the same time as this problem occurred, *ngFor
also reported a warning. It is reasonable to speculate that the problems are caused by setting standalone
.
The
*ngFor
directive was used in the template, but neither theNgFor
directive nor theCommonModule
was imported. Please make sure that either theNgFor
directive or theCommonModule
is included in the@Component.imports
array of this component.
It can be seen from the error message that the module CommonModule
needs to be introduced.
Since the component has been set to standalone and it does not have such a directive as ngFor
, it needs to be imported from CommonModule
.
Reference:Hori
So the solution is:
The problem is solved.
Solution
By analogy, the solution is: introduce the module corresponding to the instruction in the component.
Components/modules need to be introduced again, while global configuration only needs to be introduced once in the root directory.