我是Angular的新手,在显示PHP中的数据时遇到了麻烦。
我有一个view_property.php文件,该文件从属性表中调出数据,如下所示:
我认为数据库连接正常,因为控制台日志显示了来自属性表的所有详细信息,如下所示:
问题是我找不到语法错误。因为我不确定它是由于PHP文件中的json_encode还是因Angular而发生。
这是我的财产。
export class Property
{
constructor
(
id: number,
name: String,
price: number,
address: String,
nearby_places: String,
size: String,
bedroom: number,
bathroom: number,
carpark: String,
facilities: String,
furnishing: String,
manager_id: number,
property_status: String
){}
}
这是我的view-property.component.html。
<tr *ngFor="let property of allproperty; let i =index;">
<td>{{i + 1}}</td>
<td>{{property.id}}</td>
<td>{{property.name}}</td>
<td>$ {{property.price}}</td>
<td>{{property.address}}</td>
<td>
<button type="button" class="btn btn-success" (click)="getNavigation('view', property.id)">View</button>
<button type="button" class="btn btn-warning" (click)="getNavigation('update', property.id)">Edit</button>
<button type="button" class="btn btn-danger" (click)="deleteProperty('', property.id)">Delete</button>
</td>
</tr>
这是我的view-property.component.ts。
import { Component, OnInit } from '@angular/core';
import {CrudService} from '../../services/crud.service';
import {Router} from '@angular/router';
import { Property } from 'src/app/property';
@Component({
selector: 'app-view-property',
templateUrl: './view-property.component.html',
styleUrls: ['./view-property.component.css']
})
export class ViewPropertyComponent implements OnInit
{
public allproperty: any = [];
constructor(private crudService: CrudService, private router: Router) { }
ngOnInit() {
this.loadProperty();
}
loadProperty(){
this.crudService.getProperty().subscribe(
propertyData => {
this.allproperty = propertyData;
}
);
}
deleteProperty(link, id){
this.crudService.deleteProperty(id).subscribe(result => {
window.location.reload();
this.router.navigate([link]);
});
}
getNavigation(link, id){
if(id === ''){
this.router.navigate([link]);
} else {
this.router.navigate([link + '/' + id]);
}
}
}
请向我指出语法错误在哪里。非常感谢您的指导。