【发布时间】:2020-10-23 16:07:39
【问题描述】:
感谢您查看此问题。我对 Angular 很陌生,我有一个我无法弄清楚的问题。我正在做一件小事,为了练习,添加带有复选框的文本。但是,我还没有做到这一点。它失败并出现错误:
Eerror TS2345: Argument of type '{ title: string; done: false; }' is not assignable to parameter of type '{ id: number; title: string; done: boolean; }'.
Property 'id' is missing in type '{ title: string; done: false; }'.
代码是task-list.component.ts
这是我的 ts 文件。如果您需要更多信息,请告诉我。我现在一头雾水!谢谢
import {Component, ViewEncapsulation} from '@angular/core';
@Component({
selector: 'mac-task-list',
templateUrl: './task-list.component.html',
encapsulation: ViewEncapsulation.None
})
export class TaskListComponent {
tasks = [
{id: 1, title: 'Task 1', done: false},
{id: 2, title: 'Task 2', done: true}
];
addTask(title: string) { // fails here
this.tasks.push({
title, done: false
});
}
}
【问题讨论】:
-
你推送的地方,你还需要一个id..这就是抱怨..
-
谢谢,我不知道如何将 id 放入推送中。我能看到的任何地方都有 sn-p 代码吗?我所做的一切都不起作用。
标签: angular components