gpt4 book ai didi

angular - Identifier 'n' not defined, 'object'不包含这样的成员

转载 作者:太空狗 更新时间:2023-10-29 17:35:35 26 4
gpt4 key购买 nike

当我处理不在基类上的继承类型的成员并且基类在组件上声明时,Visual Studio Code (1.17.0) 在 Angular 模板中生成错误。
在下面的代码中,显然 QuestionBase 上不存在 maxLength,但我该怎么做呢?

[Angular] Identifier 'maxLength' is not defined. 'QuestionBase' does not contain such a member

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" />

关于angular - Identifier 'n' not defined, 'object'不包含这样的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46617738/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com