标识符"n"未定义,“对象"不包含此类成员 [英] Identifier 'n' not defined, 'object' does not contain such a member

查看:109
本文介绍了标识符"n"未定义,“对象"不包含此类成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从不在基类上的继承类型寻址成员并且在组件上声明了基类时,Visual Studio Code(1.17.0)在Angular模板中生成错误.
在下面的代码中,显然maxLengthQuestionBase上不存在,但是我该如何处理?

Visual Studio Code (1.17.0) generates errors in Angular templates when I address members from inherited types that are not on the base class and the base class is declared on the component.
In the code below, obviously maxLength does not exist on QuestionBase, but how do I go about this?

[角度]标识符'maxLength'未定义. 'QuestionBase'确实 不包含这样的成员

[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,因此它可以成为任何类型的问题

On the component question is declared as QuestionBase, so that it can become any kind of question

@Import question: QuestionBase

现在在html模板中,我添加了maxLength属性:

Now in the html template I addres the maxLength property:

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

这篇关于标识符"n"未定义,“对象"不包含此类成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆