angular - 无法绑定到 [(ngModel)],因为它不是由任何适用的指令提供的
问题描述
我刚开始学习 Angular,想尝试实现 2 路绑定。
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import {FormsModule} from '@angular/forms';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'sample text';
}
app.component.html
<input type="text" [(ngModel)]="title">
<p>{{title}}</p>
此代码按应有的方式运行和工作,但由于某种原因在 IDE 中(我正在使用 WebStorm)我收到此错误:
PS 是的,我阅读了与此错误相关的主题,但所有答案都说只是导入 FormsModule,我还是这样做了。
PPS 我注意到在运行 ng serve 命令之前 IDE 运行良好。
解决方案
在执行 Angular 版本更新(从 10->12)之后,我今天也遇到了 webstorm 的这个问题。Angular 12 使用较新的 Typescript 版本,我认为它在 IDE 中导致了此错误。更新到最新的 webstorm 版本为我修复了它。
推荐阅读
- r - 在R中删除格式为www的url
- powerbi - Power Bi 中的组成员
- java - 无法在 JDK13 上运行 dacapo 基准测试
- concurrency - 在以下 Clojure 代码中,alter 可以替换为 commute 吗?
- git - TFS:如何授予 NETWORK SERVICE 用户允许 git push/pull 的权限?
- java - 如何在左端设置水平滚动窗格的起始位置?
- reactjs - 如何在不刷新客户端的情况下动态指示另一个用户正在编辑记录
- python - 我们如何构建一个节点 api,它将向用户发送邮件并生成 otp 以访问我的 python 微服务
- react-native - 在一行中渲染两个图像反应原生
- python - 当我在 python 中使用列表类型变量时,我不明白逻辑。为什么它以这种方式工作?