首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角2:错误: src/app/mage/mage.component.ts (19,98):',‘预期。app/mage/mage.component.ts (19,100):无法找到名称‘response’)。

角2:错误: src/app/mage/mage.component.ts (19,98):',‘预期。app/mage/mage.component.ts (19,100):无法找到名称‘response’)。
EN

Stack Overflow用户
提问于 2017-02-02 10:18:48
回答 1查看 26关注 0票数 0

当我试图将一个角2服务连接到另一个角2组件时,出现了这个错误:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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:

代码语言:javascript
复制
export class OrdersStats {

    total:number;
    orderStatusesStats:OrderStatusStat[];
}

这是mage.service.ts:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-02 10:36:40

您不能使用箭头函数的短手样式的强制转换,应该这样编写它:

代码语言:javascript
复制
ngOnInit() {
   this.mageService.getMagentoData().subscribe((response) => {
        this.ordersStatistics = <OrdersStats>response;
   });      
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41999527

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档