我想进行路由并从本地主机获取数据。我已经在控制台上检查了数据,但是我什么也无法显示。我在终端上收到了此错误消息
ERROR in src/app/detail/detail.component.ts(19,9): error TS2322: Type 'IGames' is not assignable to type 'IGames[]'.
Property 'includes' is missing in type 'IGames'.
这是我的detail.component.ts
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { GamesService } from '../games.service';
import { IGames } from '../games';
@Component({
selector: 'app-detail',
templateUrl: './detail.component.html',
styleUrls: ['./detail.component.css']
})
export class DetailComponent implements OnInit {
id:string='';
game:IGames[]=[];
constructor(public route:ActivatedRoute, private gs:GamesService) { }
ngOnInit() {
this.id = this.route.snapshot.params['id'];
this.gs.getGamesDetail(this.id).subscribe(
(data)=>{
this.game=data;
console.log(data);
}
);
}
}
这是我的服务
getGamesDetail (id:string):Observable<IGames> {
let body = new HttpParams();
body = body.set('id', id);
return this.http.post<IGames>("http://localhost/pmn/uas/getgamesdetail.php", body);
}