【问题标题】:ngFormModal in ionic2 (error ngFormModal is not a native property)ionic2 中的 ngFormModal(错误 ngFormModal 不是本机属性)
【发布时间】:2016-09-08 11:06:44
【问题描述】:

这是我的代码,我收到类似这样的错误 例外:错误:未捕获(承诺中):模板解析错误: 无法绑定到“ngFormModel”,因为它不是已知的原生属性。

html:

<form [ngFormModel]="registrationForm">

    <ion-item>
            <ion-label floating>Email</ion-label>
            <ion-input type="email" [(ngModel)]="email" ngControl="email" ></ion-input>
          </ion-item>

          <ion-item>
            <ion-label floating>Telephone</ion-label>
            <ion-input type="number" [(ngModel)]="phoneNo" ngControl="phone" ></ion-input>
          </ion-item>


    </form>

.ts 文件:

import {FormBuilder, Validators} from '@angular/forms';
import { FORM_DIRECTIVES, REACTIVE_FORM_DIRECTIVES } from '@angular/forms';

@Component({
directives: [FORM_DIRECTIVES, REACTIVE_FORM_DIRECTIVES]
})
constructor(public _form: FormBuilder){
this.registrationForm = this._form.group({
        "email":["",Validators.compose([Validators.required, Validators.pattern('[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$')])]
}

app.ts:

    import { disableDeprecatedForms, provideForms } from '@angular/forms';

    ionicBootstrap(MyApp,[
    provideForms(),
    disableDeprecatedForms()]);

package.json:
"dependencies": {
    "@angular/common": "2.0.0-rc.4",
    "@angular/compiler": "2.0.0-rc.4",
    "@angular/core": "2.0.0-rc.4",
    "@angular/platform-browser": "2.0.0-rc.4",
    "@angular/platform-browser-dynamic": "2.0.0-rc.4",
    "@angular/http": "2.0.0-rc.4",
    "@angular/forms": "0.2.0",
    "es6-shim": "0.35.1",
    "ionic-angular": "2.0.0-beta.11",
    "ionic-native": "1.3.10",
    "ionicons": "3.0.0",
    "reflect-metadata": "0.1.8",
    "rxjs": "5.0.0-beta.6",
    "zone.js": "0.6.12"
  },

【问题讨论】:

  • 我是 ionic 新手,请帮我解决这个问题。仅在使用 ngFormModal 时出现错误。 FormBuilder,验证器正常工作。

标签: angular typescript ionic2


【解决方案1】:

您只需要在 component.ts 文件中使用 REACTIVE_FORM_DIRECTIVES。 请尝试 matheo 在以下 ionic 论坛主题中给出的非常简洁的示例。

ionic 2 form showing error

请使用上面示例中给出的包.json,以及组件ts和html文件中的导入、声明等。

【讨论】:

    猜你喜欢
    • 2018-10-01
    • 1970-01-01
    • 2016-10-17
    • 1970-01-01
    • 1970-01-01
    • 2016-10-16
    • 2021-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多