TypeScript- 的 Angular 框架错误 - “没有将 exportAs 设置为 ngForm 的指令"; [英] TypeScript-'s Angular Framework Error - "There is no directive with exportAs set to ngForm"
本文介绍了TypeScript- 的 Angular 框架错误 - “没有将 exportAs 设置为 ngForm 的指令";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用 TypeScript 的 Angular2-forms 框架时不断收到此错误:
I keep getting this error while using TypeScript's Angular2-forms framework:
没有将exportAs"设置为ngForm"的指令
这是我的代码
项目依赖:
"dependencies": {
"@angular/common": "2.0.0-rc.6",
"@angular/compiler": "2.0.0-rc.6",
"@angular/core": "2.0.0-rc.6",
"@angular/forms": "2.0.0-rc.6",
"@angular/http": "2.0.0-rc.6",
"@angular/platform-browser": "2.0.0-rc.6",
"@angular/platform-browser-dynamic": "2.0.0-rc.6",
"@angular/router": "3.0.0-rc.2",
"ng2-bootstrap": "^1.1.1",
"reflect-metadata": "^0.1.8",
"core-js": "^2.4.0",
"es6-module-loader": "^0.17.8",
"rxjs": "5.0.0-beta.11",
"systemjs": "0.19.27",
"zone.js": "0.6.17",
"jquery": "3.0.0",
}
这是登录模板:
<form #loginForm="ngForm" (ng-submit)="authenticate(loginForm.value)">
</form>
...和登录组件:
import { Component } from '@angular/core';
import {Http, Headers} from '@angular/http';
@Component({
moduleId: module.id,
selector: 'login-cmp',
templateUrl: 'login.component.html'
})
export class LoginComponent {
constructor($http: Http) {
this.$http = $http;
}
authenticate(data) {
...
}
}
我有这个错误:
zone.js?1474211973422:484 Unhandled Promise rejection: Template parse errors:
There is no directive with "exportAs" set to "ngForm" ("
<form [ERROR ->]#loginForm="ngForm"
(ngsubmit)="authenticate(loginForm.value)">
推荐答案
import { FormsModule } from '@angular/forms';
@NgModule({
imports: [
BrowserModule,
FormsModule //<----------make sure you have added this.
],
....
})
这篇关于TypeScript- 的 Angular 框架错误 - “没有将 exportAs 设置为 ngForm 的指令";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文