我正在尝试向我的组件注入一个服务,我想我已经正确地编写了所有内容,但它给了我一个错误Constructor Implementation is missing
。
我的组件是
import { Component, OnInit } from '@angular/core';
import {Lists} from "./lists";
import {ListsService} from "./lists.service";
@Component({
selector: 'app-lists',
templateUrl: './lists.component.html',
styleUrls: ['./lists.component.css']
})
export class ListsComponent implements OnInit {
lists: Lists[] = [];
constructor(private listService: ListsService){}
ngOnInit() {
this.lists = this.listService.getItems();
}
}
我的服务
import {Lists} from "./lists";
export class ListsService {
private lists: Lists[] = [];
addLists(list: Lists){
this.lists.push(list);
console.log(`You added ${list}`)
}
getItems(){
return this.lists;
}
}
我的模板是
<app-lists-edit></app-lists-edit>
<app-lists-row *ngFor="let list of lists" [item]="list"></app-lists-row>
我在这里做的任何事都是错误的。我甚至在ngmodule的提供者中输入了服务。
其他错误
错误
RROR in C:/Sites/Angular2main/todolist/src/app/lists/lists.ts (2,15): A parameter property is only allowed in a constructor implementation.
ERROR in C:/Sites/Angular2main/todolist/src/app/lists/lists.ts (3,15): A parameter property is only allowed in a constructor implementation.
ERROR in C:/Sites/Angular2main/todolist/src/app/lists/lists.ts (4,15): A parameter property is only allowed in a constructor implementation.
ERROR in C:/Sites/Angular2main/todolist/src/app/lists/lists.ts (4,15): A parameter initializer is only allowed in a function or constructor implementation.
我的错误在于我的模型
export class Lists {
constructor(private title: string, private description: string, private completed: boolean)
}
我的构造函数之后没有放大括号。