2016-01-31 7 views
10

stavo seguendo questo campione da https://angular.io/docs/ts/latest/guide/router.htmlts1109: espressione di errore angolare previsto

e io sto cercando di fare una lista simile con un servizio pure, ma qualche ragione quando scrivo questa linea

servingpatients = Patient[]; 

nel mio componente, sto ricevendo questo errore, se lo rimuovo, la cosa funziona. Non sono sicuro che cosa stia cercando di fare nell'esempio. Errore di console: errore

Uncaught SyntaxError: Unexpected token ]

terminale durante la compilazione tipi

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

} 

risposta

27

L'errore dice on line (35,27), ma vedo solo 11 righe qui in dashboard.component.ts.

Guardando il tuo copione, l'unico problema è qui. Si sta definendo il tipo per "servingpatients" come serie di "Paziente"

servingpatients = Patient[]; 

favore cambia uguale (=) a due punti (:) per definire il tipo

servingpatients : Patient[]; 
+0

Sì che era il problema, din non me ne accorgo. Grazie. –