我在Angular2定義的形式類似:問題與Angular2打字稿編譯窗體
this.form = this._formBuilder.group({
password: ['',Validators.required],
passwordRepeat: ['',Validators.required]
});
其中
public form:ControlGroup
這很好,因爲:
_formBuilder = FormBuilder.group(controlsConfig: {
[key: string]: any;
}, extra?: {
[key: string]: any;
}): modelModule.ControlGroup
返回ControlGroup
。現在
,在我的組件我使用:
this.user.password = this.passwordEditForm.controls.password.value;
會拋出我的編譯錯誤:
error TS2339: Property 'password' does not exist on type '{ [key: string]: AbstractControl; }'.
似乎是一個錯誤。關於如何克服這個問題的任何想法?我試着這樣做:
export interface FormControlGroup extends ControlGroup{
password:any;
}
但是這給了我更多的錯誤:
error TS1206: Decorators are not valid here.
app/form.component.ts(30,9): error TS2322: Type 'ControlGroup' is not assignable to type 'FormControlGroup'.
Property 'password' is missing in type 'ControlGroup'.
app/form.component.ts(37,61): error TS2339: Property 'password' does not exist on type '{ [key: string]: AbstractControl; }'.
您使用的是哪個版本的Angular2? –
角2 2.0.0-beta.8 – uksz