我正在尝试实现angular2反应形式,但在加载组件时出现运行时错误
未捕获的TypeError:无法设置只有getter的[object Object]的属性堆栈
这个错误并不完全清楚,所以我很难弄清楚发生了什么.我跟着一个angular university article.我想也许有一些重大的变化,所以我检查了angular2更改日志,但没有发现任何与我的问题有关的反应形式.
任何帮助将在这里受到赞赏.我将继续寻找解决方案.
addevent.component.ts
@Component({ selector: 'addevent',templateUrl: 'addevent.component.html',styleUrls: ['addevent.scss'] }) export class AddEvent { // vars private _addEventForm:FormGroup; private _eventTitle:FormControl; private _eventDescription:FormControl; constructor(private _addEventService:AddEventService,private _formBuilder:FormBuilder) { // init vars this. _eventTitle = new FormControl('',Validators.required); this._eventDescription = new FormControl('',Validators.required); this._addEventForm = _formBuilder.group({ 'eventTitle': this._eventTitle,'eventDescription': this._eventDescription }); } private addEvent():void { console.log(this._addEventForm); //this._addEventService.addEvent(); } }
addevent.component.html
<div class="h3 content-title">Add Event</div> <form [formGroup]="_addEventForm" (ngSubmit)="addEvent()"> <p> <label>Title</label> <input type="text" formControlName="eventTitle"> </p> <p> <label>Description</label> <input type="text" formControlName="eventDescription"> </p> <p> <button type="submit" [disabled]="_addEventForm.invalid">Submit</button> </p> </form>
dashboard.module.ts
@NgModule({ declarations: [Dashboard,Navbar,Sidebar,Home,Profile,Events,AddEvent],imports: [BrowserModule,FormsModule,ReactiveFormsModule,HttpModule],providers: [ContentSwap,SidebarActivity,AuthService,FirebaseAuthService] }) export class DashboardModule {}