2016-08-14 153 views
3

我刚刚完成了RC4的更新;然而,许多事情停止工作,下面的工作正常。 现在,ngModel不会在里面工作,除非你删除其中的一个。更新到rc4后,Angular 2 - ngModel无法工作<form>

page.js

import {Component} from '@angular/core'; 

page.html中

<form (ngSubmit)="submitForm()"> 
     <ion-list radio-group [(ngModel)]="content" name="ionListGroup"> 
     </ion-list> 
    </form> 

当我点击打开page.html中,什么也没有发生,但我看到:

*It looks like you're using the old forms module. This will be opt-in in the next RC, and 
    will eventually be removed in favor of the new forms module. For more information, see: 
    https://docs.google.com/document/u/1/d/1RIezQqE4aEhBRmArIAS1mRIZtWFf6JxN_7B4meyWK0Y/pub 

我已经做了一些调试,我已经看到,如果我删除[(ngModel)]="content"<form>标签的一切工作再好,但我CA不要删除它们中的任何一个,因为我需要它们。

回答

0

从错误消息中提到的文档。您需要以下步骤

import {disableDeprecatedForms, provideForms} from '@angular/forms'; 
bootstrap(AppComponent, [ 
    disableDeprecatedForms() 
    provideForms() 
]) 
0

1.包含在app.module.ts形式模块NgModule文件

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

    @MgModule({ 
    imports: [ 
     ... 
     FormsModule, 
     ... 
    ])} 

2.不要忘了给一个名称输入元素

<input mdInput type="text" [(ngModel)]="username" placeholder="User Name" name="first" required>