我正在尝试构建一个应用程序,在这个应用程序中,我想首先按用户获取我的帖子,然后当点击某个帖子时,我想通过id获取该特定的帖子。
最终,我得到了以下错误:
ERROR in src/app/cars/car-detail/car-detail.component.ts(25,11): error TS2322: 类型'Observable<{ _id: string; title: string; content: string; imagePath: string; creator: string; }>'不能赋值给类型'Car[]'。
类型'Observable<{ _id: string; title: string; content: string; imagePath: string; creator: string; }>'中缺少属性'includes'。
src/app/cars/car-detail/car-detail.component.ts(26,11): error TS2322: 类型'number'不能赋值给类型'string'。
最终,我得到了以下错误:
ERROR in src/app/cars/car-detail/car-detail.component.ts(25,11): error TS2322: 类型'Observable<{ _id: string; title: string; content: string; imagePath: string; creator: string; }>'不能赋值给类型'Car[]'。
类型'Observable<{ _id: string; title: string; content: string; imagePath: string; creator: string; }>'中缺少属性'includes'。
src/app/cars/car-detail/car-detail.component.ts(26,11): error TS2322: 类型'number'不能赋值给类型'string'。
import { Input, Component, OnInit } from '@angular/core';
import { Car } from '../car.model';
import { CarsService } from '../cars.service';
import { ActivatedRoute, Params } from '@angular/router';
@Component({
selector: 'app-post-detail',
templateUrl: './post-detail.component.html',
styleUrls: ['./post-detail.component.css']
})
export class PostDetailComponent implements OnInit {
@Input() post: Post[] = [];
@Input() id: string;
constructor(
private postsService: PostsService,
private route: ActivatedRoute
) { }
ngOnInit() {
this.route.params
.subscribe(
(params: Params) => {
this.post = this.postsService.getPost(this.id);
this.id = +params['id'];
}
);
}
}
我应该怎么办?