ts1109 : expression expected angular error

Bala Sivagnanam picture Bala Sivagnanam · Jan 31, 2016 · Viewed 36k times · Source

I was following this sample from https://angular.io/docs/ts/latest/guide/router.html

and I am trying to do a similar list with a service as well, but some reason when I write this line

servingpatients = Patient[];

in my component, I am getting this error, if I remove it, the thing works. Not sure what this is trying to do in the sample though. console error:

Uncaught SyntaxError: Unexpected token ]

terminal error during types compilation

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

}

Answer

Siva picture Siva · Jan 31, 2016

The error says on line (35,27) but i can see only 11 lines here in dashboard.component.ts.

Looking at your script, The only issue is here. You are defining the type for "servingpatients" as array of "Patient"

servingpatients = Patient[];

Please change equal (=) to colon (:) to define the type

servingpatients : Patient[];