小编taz*_*zza的帖子

Angular TypeError:在尝试调用object.object [].方法时不是函数

当我尝试在角度4中调用object.object [].方法的方法时,我收到以下错误:

OrderComponent.html:30 ERROR TypeError:item.increaseQuantity不是OrderComponent.increaseQuantity中的函数(order.component.ts:87)

我的打字稿代码如下.当我调用OrderComponent.IncreaseQuantity(itemLoc:number)方法时,当我尝试在方法中调用this.orderItems [itemLoc] .increaseQuantity()方法时,它会生成上面的错误.我不知道为什么它不知道OrderItem.increaseQuantity方法:

import { Component, Inject } from '@angular/core';
import { Http } from '@angular/http';

class OrderItem {
    id: number;
    name: string;
    unitPrice: number;
    quantity: number;
    amount: number;
    comment: string;

    increaseQuantity(): boolean {
        console.log("In the Order Item itself - worked.");
        this.quantity += 1;
        this.amount = this.quantity * this.unitPrice;
        return false;
    }
}

class Order {
    id: number;
    createdTime: Date;
    orderType: string;
    tableName: string;
    orderItems: OrderItem[];
}

@Component({
    selector: 'order',
    templateUrl: './order.component.html'
})
export class …
Run Code Online (Sandbox Code Playgroud)

function typeerror typescript angular

4
推荐指数
1
解决办法
3903
查看次数

禁用时如何更改 Angular 5 材质垫选择所选文本中的样式

当设置为禁用时,如何更改显示来自 Angular 5 材料垫选择的选定值的文本上的字体颜色。目前它默认为灰色,我想更改它,以便它在禁用和启用时显示深蓝色。

  <mat-form-field>
    <mat-select placeholder="Select a Product" [(ngModel)]="selected" [disabled]="isDisabled" panelClass="my-select-panel-class">
      <mat-option *ngFor="let prod of products" [value]="prod.productID">
        {{ prod.key }}
      </mat-option>
    </mat-select>
  </mat-form-field>
Run Code Online (Sandbox Code Playgroud)

css colors angular-material angular

2
推荐指数
1
解决办法
1万
查看次数