类型“对象”上不存在属性“方向”

时间:2019-10-01 13:06:41

标签: angular typescript

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

如何解决此问题,因为Direction和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"

2 个答案:

答案 0 :(得分:0)

在打字稿中,通常这样定义一个类“ exampleclass”(exampleclass.ts):

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

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

答案 1 :(得分:0)

您将ngcFloatButtonData声明为Object。声明它为NgcFloatButtonComponent,而不是它。 (从您正在使用的库中导入NgcFloatButtonComponent

相关问题