Javascript 角度2+;错误-未捕获错误:模板分析错误:没有带“的指令”;exportAs";设置为";ngModel";(“集团”;
我使用的是角度2+形式 详细错误: 未捕获错误:模板分析错误: 没有将“exportAs”设置为“ngModel”(“-group”> 名字 ]#firstName=“ngModel”(更改)=“log(firstName)”id=“firstName”class=“form control”> ) 在JitCompiler.\u compileComponents(compiler.js:25895) 在compiler.js:25808 在Object.then(compiler.js:2166) 在JitCompiler._compileemoduleandcomponents(compiler.js:25807) 下面是我的contact-form.component.html页面:Javascript 角度2+;错误-未捕获错误:模板分析错误:没有带“的指令”;exportAs";设置为";ngModel";(“集团”;,javascript,angular,forms,Javascript,Angular,Forms,我使用的是角度2+形式 详细错误: 未捕获错误:模板分析错误: 没有将“exportAs”设置为“ngModel”(“-group”> 名字 ]#firstName=“ngModel”(更改)=“log(firstName)”id=“firstName”class=“form control”> ) 在JitCompiler.\u compileComponents(compiler.js:25895) 在compiler.js:25808 在Object.then(compiler.js:21
<form>
<div class="form-group">
<label for="firstName">First Name</label>
<input required ngModel name="firstName" #firstName = "ngModel" (change) ="log(firstName)" id="firstName" class="form-control">
<div class="alert alert-danger" *ngIf = "!firstName.valid">First Name is required</div>
</div>
<div class="form-group">
<label for="comment">Comment</label>
<textarea ngModel name ="comment" id="comment" cols="30" rows="10" class="form-control"></textarea>
</div>
<button class="btn btn-primary">Submit</button>
</form>
below is my contact-form.component.ts page :
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'contact-form',
templateUrl: './contact-form.component.html',
styleUrls: ['./contact-form.component.css']
})
export class ContactFormComponent {
log(x) {
console.log(x);
}
}
名字
名字是必需的
评论
提交
以下是我的联系方式-form.component.ts页面:
从“@angular/core”导入{Component,OnInit};
@组成部分({
选择器:'联系方式',
templateUrl:“./contact form.component.html”,
样式URL:['./联系表单.component.css']
})
导出类ContactFormComponent{
对数(x){
控制台日志(x);
}
}
您似乎在混合这两种形式和方法。而不是:
<input required ngModel name="firstName" #firstName = "ngModel" (change)="log(firstName)" id="firstName" class="form-control">
显示您的
app.module.ts
或您定义的模块从“@angular/platform browser”导入{BrowserModule};从“@angular/core”导入{NgModule};从“/app routing.module”导入{appointgmodule};从“/app.component”导入{AppComponent};从“/course/course.component”导入{CourseComponent};导入{SummaryPipe}来自./summary.pipe';导入{PanelComponent}来自./panel.component';导入{InputFormatDirective}来自./InputFormat.directive';导入{ContactFormComponent}来自./contact form/contact form.component';@NgModule({声明:[AppComponent,CourseComponent,SummaryPipe,PanelComponent,InputFormatDirective,ContactFormComponent,],导入:[BrowserModule,AppRoutingModule],引导:[AppComponent]})导出类AppModule{}
<input required [(ngModel)]="firstName" name="firstName" id="firstName" class="form-control">