小编yea*_*021的帖子

Angular 12 - 不可分配给类型 '[number, number]

我正在 Angular 12 中尝试 ngx-charts 库,但我不断遇到这个问题:

类型“any[]”不可分配给类型“[number, number]”。

目标需要 2 个元素,但源可能更少。

我不知道这个错误意味着什么。

这是代码:

HTML:

<ngx-charts-linear-gauge 
  [view]="view" 
  [scheme]="colorScheme" 
  [value]="value" 
  [previousValue]="previousValue" 
  (select)="onSelect($event)" 
  [units]="units"
>
</ngx-charts-linear-gauge>
Run Code Online (Sandbox Code Playgroud)

TS:

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {

  single: any[];
  view: any[] = [400, 400];
  colorScheme = {
    domain: ['#aae3f5']
  };
  value: number = 43;
  previousValue: number = 70;
  units: string = 'counts';

  onSelect(event) {
    console.log(event);
  }

}
Run Code Online (Sandbox Code Playgroud)

关于错误的含义以及如何解决这个问题有什么想法吗?

ts配置代码是:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": …
Run Code Online (Sandbox Code Playgroud)

angular ngx-charts angular12

3
推荐指数
1
解决办法
2688
查看次数

标签 统计

angular ×1

angular12 ×1

ngx-charts ×1