我的问题是我无法在Angular 2中获得要在模板上显示的“total”变量。 这是mage.component.ts:
import { Component } from '@angular/core';
import { MageService } from './mage.service';
import { OrdersStats } from './orders.stats';
import { OrderStatusStat} from './order.status.stat';
@Component({
selector: 'my-mage',
templateUrl: './mage.component.html',
styleUrls:['./mage.component.css']
})
export class MageComponent {
ordersStatistics:OrdersStats;
constructor(private mageService: MageService) { }
ngOnInit() {
this.mageService.getMagentoData().subscribe(response => <OrdersStats>this.ordersStatistics = response);
}
}
这是orders.stats.ts:
export class OrdersStats {
total:number;
orderStatusesStats:OrderStatusStat[];
}
这是mage.service.ts:
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { Response } from '@angular/http';
import { OrderStatusStat } from './order.status.stat';
import { OrdersStats } from './orders.stats';
import 'rxjs/add/operator/map';
@Injectable()
export class MageService {
constructor(private http: Http) { }
getMagentoData() {
return this.http.get("http://localhost:80/angular2/ng2/middleware/MiddleWare.php")
.map(response => <OrdersStats>response.json().data);
}
}
这是orders.status.stat.ts:
export class OrderStatusStat {
status:string; //Name of the status
count:number; //How many orders with this status
totalAmount:number; //Total amount of all orders with this status
}
这是mage.component.html,它挂钩到mage.component.ts:
<main class="container" role="main">
ORDERS<br/><br/>
TOTAL: {{ ordersStatistics.total }}<br/><br/>
</main>
我在这里缺少什么?在Angular 2中,调试变量,查看其中的内容的最佳方法是什么?我需要看看是否正在填充“总数”,以及内部是什么。