将一个 component 转换为 standalone component
<div>
<cnb-spinner [show]="isLoading">
<cnb-editors-selector [(ngModel)]="defaultEditor"></cnb-editors-selector>
</cnb-spinner>
</div>
[(ngModel)]
报错:
Can't bind to 'ngModel' since it isn't a known property of 'cnb-editors-selector'.
在 imports
中添加 NgModel
import { NgModel } from '@angular/forms';
@Component({
imports: [NgModel]
})
却报错不支持 import NgModel
The directive 'NgModel' appears in 'imports', but is not standalone and cannot be imported directly. It must be imported via an NgModule.
请问如何解决这个问题?
改为 FormsModule 就可以了
import { FormsModule } from '@angular/forms';
@Component({
imports: [FormsModule]
})