为什么(ngModel)不起作用? [英] Why (ngModel) is not working?

查看:193
本文介绍了为什么(ngModel)不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在运行示例应用程序以学习角度2.在我的示例应用程序中,[(ngModel)]无法正常工作.但是,当我移除方括号(ngModel)时,屏幕正在加载,但是双向绑定不起作用.

I have running the sample application to learn angular 2. In my sample application [(ngModel)] is not working. But when i removes the square brackets (ngModel) the screen is loading but two way binding is not working.

我应该做些什么来使[(ngModel)]工作.

should i do anything for making [(ngModel)] work.

推荐答案

您的代码可能缺少模块中的此导入行:

Probably your code is missing this import line in your module:

import { FormsModule } from '@angular/forms';

您还必须将FormsModule添加到模块导入数组:

You also have to add FormsModule to module imports array:

@NgModule({
   imports:      [FormsModule, /*...*/ ],
   //...
})

这篇关于为什么(ngModel)不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆