当我试图将一个角2服务连接到另一个角2组件时,出现了这个错误:
ERROR in ./src/app/mage/mage.component.ts
Module build failed: Error: /Applications/MAMP/htdocs/angular2/ng2/src/app/mage/mage.component.ts (19,98): ',' expected.)
/Applications/MAMP/htdocs/angular2/ng2/src/app/mage/mage.component.ts (19,100): Cannot find name 'response'.)为什么会发生这种情况?如果可能的话,试着帮我,不要投反对票,因为这是我第二天第二次用角度2,我很大程度上是个角质2的菜鸟。我好心地问这个问题,因为我的最后一个2角问题被否决了,并进入了负值。谢谢你没有否定地把我带到地狱的深处:)
这是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
}发布于 2017-02-02 10:36:40
您不能使用箭头函数的短手样式的强制转换,应该这样编写它:
ngOnInit() {
this.mageService.getMagentoData().subscribe((response) => {
this.ordersStatistics = <OrdersStats>response;
});
}https://stackoverflow.com/questions/41999527
复制相似问题