首页 > 解决方案 > “对象”类型不存在属性“方向”

问题描述

我正在使用带有浮动操作按钮的 Angular 7.x 应用程序,当我执行以下命令以在生产模式下构建时,我在终端中遇到了一些错误。

由于方向和 onToggle 已经存在,我该如何解决这个问题?

src\app\components\calendar\calendar.component.html(202,9): : Property 'direction' does not exist on type 'Object'.
src\app\components\calendar\calendar.component.html(201,9): : Property 'onToggle' does not exist on type 'Object'.

// HTML 组件

// 打字稿组件

    // 
    ngcFloatButtonData: Object = {
        direction: 'up',
        open:false,
        onToggle: function(): void {
            this.open = !this.open;
        },
    };

// HTML

<ngc-float-button
  (click)="ngcFloatButtonData.onToggle()"
  [direction]="ngcFloatButtonData.direction"

标签: angulartypescript

解决方案


在打字稿中,通常定义一个类“exampleclass”(exampleclass.ts),如下所示:

export class exampleclass {
    propertyOne: number;
    propertyTwo: String;
    propertThree: number;
}

还要确保您要在模板中访问的属性具有正确的范围 -> public


推荐阅读