1-1app.modult.ts中配置
//1.在app.module.ts根目录中导入并注册
import {FormsModule} from '@angular/forms'
@NgModule({
...
imports: [
...
FormsModule //注册
],
...
})
1-2在组件中使用
//.component.ts
export class HeaderComponent implements OnInit {
public msg:string='hello world';
...
}
}
//.html
<input type="text" [(ngModel)]="msg"> // [(ngModel)]="msg" 快捷键ng就可以出来