=>field-base.ts
export class FieldBase {
value: T;
key: string;
label: string;
required: boolean;
pattern: string;
order: number;
controlType: string;
constructor(options: {
value?: T,
key?: string,
label?: string,
required?: boolean,
pattern?: string,
order?: number,
controlType?: string
} = {}) {
this.value = options.value;
this.key = options.key || ‘’;
this.label = options.label || ‘’;
this.required = options.required;
this.pattern = options.pattern || ‘’;
this.order = options.order === undefined ? 1 : options.order;
this.controlType = options.controlType || ‘’;
}
}
=>field-radio.ts
import { FieldBase } from ‘./field-base’;
export class FieldRadio extends FieldBase {
controlType = ‘radio’;
type: string;
items: { name: string, value: string}[] = [];
constructor(options: any) {
super(options);
this.items = options.items || [];
this.type = ‘radio’;
}
}
在範例裡的 Component裡ts檔裡,有
@Input() field: FieldBase<any>;
而在HTML裡的存取,關於field.items這些非FieldBase屬性。同樣程式碼在我自己建置專案會出現錯誤,如items not defind…而範例卻不會,範例的angular/core是5.0.0,我的是9.1.7。
不太了解的是依一般繼承本來FieldBase就不可能讀取到radio的屬性。請問這部份該如何修改或是我自己那邊用錯了嗎?
因為整個範例滿多東西我也不好全貼上,我所說作動的HTML網址如下: