2016-04-11 2 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/платформы/браузера «; импорт {AppComponent} из "./app.component"; импорт {HTTP_PROVIDERS} из "angular2/http"; bootstrap (AppComponent, [HTTP_PROVIDERS]); – Satch3000

ответ

1

Вы должны удалить скобки сразу после имени класса:

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

вместо

@Injectable() 
export class DataService() { // <----------- 
Смежные вопросы