Angular 2 - 更新到 rc4 后,ngModel 无法在
内工作

2024-02-10

我刚刚更新了 RC4;然而,很多事情都停止工作了,下面的工作正常。 现在,除非删除其中之一,否则 ngModel 无法在内部工作。

page.js

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

页面.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" or <form>标记一切再次正常工作,但我无法删除其中任何一个,因为我需要它们。


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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Angular 2 - 更新到 rc4 后,ngModel 无法在 内工作 的相关文章

随机推荐