ts1109: 表达式预期,Angular 错误

18

我正在按照https://angular.io/docs/ts/latest/guide/router.html的示例进行操作。

我也想使用服务来创建类似的列表,但是出现了问题,当我编写以下这行代码时:

servingpatients = Patient[];

在我的组件中,如果我移除下面这段代码,程序就可以运行。但是不确定这段代码在示例中的作用。

Uncaught SyntaxError: Unexpected token ]

在类型编译期间出现了终端错误:

app/dashboard/dashboard.component.ts(35,27):error TS1109: Expression expected

dashboard.component.ts

import {Component, OnInit} from 'angular2/core';
import {Patient, DashboardService} from './dashboard.service';
import {Router} from 'angular2/router';
export class DashboardComponent implements OnInit{

servingpatients = Patient[];

  constructor(private _service : DashboardService,
    private _router: Router){}


  ngOnInit(){
  this._service.getServingPatients().then(servingpatients => this.servingpatients = servingpatients)
  }

}
1个回答

42

错误显示在第(35,27)行,但我在dashboard.component.ts这里只看到11行。

根据您的脚本,唯一的问题就在这里。您将"servingpatients"的类型定义为"Patient"数组。

servingpatients = Patient[];
请将等号(=)更改为冒号(:)以定义类型
servingpatients : Patient[];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接