我刚刚开始在Angular2工作。现在,我在向Form添加表单指令时遇到问题。我关注了html表单。为了简单起见,我只是在这里放置必要的字段。我已将我的组件命名为类别。
以下是类别模型
export class Category {
Title: string;
Description: string;
constructor(Title: string, Description: string) {
this.Title = Title;
this.Description = Description;
}
}
以下是 category.template 文件
<form #form="ngForm" (ngSubmit)="onSubmit()" novalidate>
<div class="form-group">
<label>Title</label>
<input [(ngModel)]="model.Title" #title="ngModel" name="title" id="title" type="text" class="form-control" value="">
</div>
<div class="form-group">
<label>Description</label>
<textarea [(ngModel)]="model.Description" #description="ngModel" class="summernote form-control" name="description" id="description"></textarea>
</div>
</form>
以下是 category.component
import { Component } from '@angular/core';
import { FormBuilder} from '@angular/forms';
import { Category } from '../../../models/cms/Category';
@Component({
selector: 'category',
templateUrl: 'category.template.html'
})
export class CategoryComponent{
model = new Category("dummyTitle","dummyDescription");
onSubmit() {
console.log(this.data);
}
}
这是我得到的错误。
Template parse errors:
There is no directive with "exportAs" set to "ngForm" ("
<form [ERROR ->]#form="ngForm" (ngSubmit)="onSubmit()" novalidate>
请帮我解决此错误。