Visual Studio Code(1.17.0)Angular
は、基本クラスにない継承された型からメンバーをアドレス指定し、基本クラスがコンポーネントで宣言されている場合、テンプレートでエラーを生成します。
以下のコードでは、明らかににmaxLength
存在しませんがQuestionBase
、どうすればこれを実行できますか?
[角度]識別子 'maxLength'が定義されていません。「QuestionBase」にはそのようなメンバーは含まれていません
export class QuestionBase {
id: number;
order: number;
}
export class TextQuestion extends QuestionBase {
maxLength: number
}
コンポーネントでは、質問はQuestionBaseとして宣言されているため、あらゆる種類の質問になる可能性があります。
@Import question: QuestionBase
ここで、htmlテンプレートにmaxLengthプロパティを追加します。
<input type="text" class="form-control" id="maxLength" [(ngModel)]="question.maxLength" name="maxLength" />
このようにしてみてください:
QuestionBase.ts
export class QuestionBase {
id: number;
order: number;
}
export class TextQuestion extends QuestionBase {
maxLength: number
}
component.ts
import { QuestionBase } from './';
export class Component {
private question: QuestionBase = new QuestionBase();
constructor() { }
}
component.html
<input type="text" class="form-control" id="maxLength" [(ngModel)]="question.maxLength" name="maxLength" />
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加