
【angular报错】组件设置standalone后:Can‘t bind to ‘ngModel‘ since it isn‘t a known property of ‘input‘.
由于组件已经被设置为standalone,而它本身并没有。以此类推,解决方法为:在组件中引入对应指令的模块。在练习路由的组件懒加载的时候,将组件设置为。搜了很多解决方法,都是直接import导入。,然后组件对应的html中使用的。由报错内容可知,需要引入。在出现这个问题的同时,
背景
在练习路由的组件懒加载的时候,将组件设置为standalone
,然后组件对应的html中使用的*ngModel
报错:
Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’.
搜了很多解决方法,都是直接import导入FormsModule
这个模块解决的。
题外话
在出现这个问题的同时,*ngFor
也报警告了。合理推测都是由设置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.
由报错内容可知,需要引入CommonModule
这个模块。
由于组件已经被设置为standalone,而它本身并没有ngFor
这种指令,需要从CommonModule
中导入。
参考:这里
因此,解决方法为:
问题解决了。
解决方法
以此类推,解决方法为:在组件中引入对应指令的模块。
组件/模块 要用到的东西,要再次引入,而全局配置只需在根目录引入一次。
更多推荐
所有评论(0)