2016-04-11 55 views
0

我有這樣的服務:錯誤的構造

import {Injectable} from 'angular2/core'; 
import {Http, Headers} from 'angular2/http'; 
import 'rxjs/Rx'; 

@Injectable() 

export class DataService() { 

    constructor(private _http: Http) {} 


} 

這是引發此錯誤:

Error: Zone</[email protected]://localhost:3000/node_modules/angular2/bundles/angular2-polyfills.js:1243:21 
    [email protected]://localhost:3000/node_modules/angular2/bundles/angular2-polyfills.js:1220:21 
    [email protected]://localhost:3000/node_modules/angular2/bundles/angular2-polyfills.js:468:17 
    [email protected]://localhost:3000/node_modules/angular2/bundles/angular2-polyfills.js:480:18 
    [email protected]://localhost:3000/node_modules/angular2/bundles/angular2-polyfills.js:451:12 
    @http://localhost:3000/node_modules/angular2/bundles/angular2-polyfills.js:123:10 
    Zone</[email protected]://localhost:3000/node_modules/angular2/bundles/angular2-polyfills.js:1243:21 
    [email protected]://localhost:3000/node_modules/angular2/bundles/angular2-polyfills.js:1220:21 
    [email protected]://localhost:3000/node_modules/angular2/bundles/angular2-polyfills.js:262:10 

    Evaluating http://localhost:3000/app/data.service.js 
    Error loading http://localhost:3000/app/data.service.js as "./data.service" from http://localhost:3000/app/app.component.js 
addToError() 

任何想法,爲什麼?

+0

是的,這是我的root.ts: 進口{}舉從「angular2 /平臺/瀏覽器「; 從「./app.component」導入{AppComponent}; 從「angular2/http」導入{HTTP_PROVIDERS}; bootstrap(AppComponent,[HTTP_PROVIDERS]); – Satch3000

回答

1

你應該在類名之後刪除括號:

@Injectable() 
export class DataService { // <----------- 

,而不是

@Injectable() 
export class DataService() { // <-----------