【问题标题】:I'm getting an error TS1109: Expression expected in angular project im working on我收到错误 TS1109:我正在处理的角度项目中预期的表达式
【发布时间】:2023-02-03 23:08:52
【问题描述】:

我正在关注这个 https://developers.google.com/codelabs/building-a-web-app-with-angular-and-firebase#4 教程,我在第 11 行收到错误:todo: Task[] = [...]; 在教程中它没有说明这个错误,我被卡住了。

import { Component } from '@angular/core';
import { Task } from './task/task';
import { CdkDragDrop, transferArrayItem } from '@angular/cdk/drag-drop';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent {
  todo: Task[] = [...];
  inProgress: Task[] = [];
  done: Task[] = [];

  editTask(list: string, task: Task): void {}

  drop(event: CdkDragDrop<Task[]>): void {
    if (event.previousContainer === event.container) {
      return;
    }
    if (!event.container.data || !event.previousContainer.data) {
      return;
    }
    transferArrayItem(
      event.previousContainer.data,
      event.container.data,
      event.previousIndex,
      event.currentIndex
    );
  }
}

我试图检查和更新打字稿版本,但没有任何变化。

【问题讨论】:

    标签: angular


    【解决方案1】:

    todo: Task[] = [...] 是无效语法。

    它应该是 []Task 对象的有效数组(这可能是教程所暗示的)。不过,仅通过查看代码,我很想说 todo: Task[] = [] 更合适

    【讨论】:

    • 是的,我刚刚找到了那个教程的 github,我认为那 3 个点是传播运算符,但它实际上指出我需要在数组中放置一些硬编码数据。我的错。但还是谢谢你:)
    【解决方案2】:

    我想你应该添加上一课的数组数据 https://developers.google.com/codelabs/building-a-web-app-with-angular-and-firebase#3

    todo: Task[] = [
        {
          title: 'Buy milk',
          description: 'Go to the store and buy milk'
        },
        {
          title: 'Create a Kanban app',
          description: 'Using Firebase and Angular create a Kanban app!'
        }
      ];
    

    或者你可以使用一个空数组 []

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-02
      • 2023-04-08
      • 2016-06-19
      • 2016-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-11
      相关资源
      最近更新 更多