【问题标题】:ts1109 : expression expected angular errorts1109:表达式预期的角度错误
【发布时间】:2016-01-31 08:05:01
【问题描述】:

我从https://angular.io/docs/ts/latest/guide/router.html关注这个样本

我也在尝试用服务做一个类似的列表,但是当我写这行时出于某种原因

servingpatients = Patient[];

在我的组件中,我收到了这个错误,如果我删除它,事情就会起作用。 不过,不确定这是在示例中尝试做什么。 控制台错误:

Uncaught SyntaxError: Unexpected token ]

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

app/dashboard/dashboard.component.ts(35,27):error TS1109: 表达式 预计

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)
  }

}

【问题讨论】:

    标签: angular angular2-services


    【解决方案1】:

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

    看看你的脚本,唯一的问题就在这里。您将“服务患者”的类型定义为“患者”数组

    servingpatients = Patient[];
    

    请将等号 (=) 改为冒号 (:) 来定义类型

    servingpatients : Patient[];
    

    【讨论】:

      猜你喜欢
      • 2021-01-02
      • 2023-04-08
      • 2016-06-19
      • 2016-06-19
      • 2023-02-03
      • 2018-06-11
      • 2020-06-29
      • 2011-12-25
      • 1970-01-01
      相关资源
      最近更新 更多