有以下代码:
import { Component, Directive } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';
import { Http, Response, Headers } from '@angular/http';
import { Router, ActivatedRoute, Params } from '@angular/router';
@Component({
selector: 'app-room-details',
templateUrl: './room-details.component.html',
styleUrls: ['./room-details.component.css']
})
export class RoomDetailsComponent {
public sobe: any = [];
http: Http;
router: Router;
route: ActivatedRoute;
data: Object[];
public id: string;
constructor(route: ActivatedRoute, http: Http, router: Router) {
this.http = http;
this.router = router;
this.route = route;
}
ngOnInit() {
this.id = this.route.snapshot.paramMap.get('id');
let hisid=+this.id;
console.log(hisid);
let headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
headers.append("token",localStorage.getItem("token"));
this.http.get('http://localhost/it255/getroom.php?id='+hisid,{headers:headers}).subscribe( data => {
this.room = JSON.parse(data['_body']).rooms;
console.log(this.room);
},
err=> { alert("No rooms");});
}}
html:
<table class="table" align="center">
<thead>
<tr>
<th>Name</th>
<th>Num beds</th>
<th>TV</th>
</tr>
</thead>
<tbody>
<tr *ngIf="room">
<td>{{room.roomname}}</td>
<td>{{room.beds}}</td>
<td>
<span *ngIf="room.tv == '1'">
TV: Yes
</span>
<span *ngIf="room.tv != '1'">
TV: No
</span>
</td>
</tr>
</tbody>
请问代码中哪出错了,该如何解决呢?
发布于 2018-07-26 12:28:41
查看DevTools,从服务器获得内容(Networktab)
发布于 2018-07-26 13:18:56
丢失了.json();所以导致house=data.json();
https://stackoverflow.com/questions/-100005778
复制相似问题