Angular 2 Service Error. I can not find the reason

I am new to Angular and stuck for some time. I'm trying to make a service that receives data from an internal webapi, it worked before that, but now it gives an error that I can not solve. I hope one of you guys can help me ... Service:

import {Injectable} from "@angular/core";
import {Http} from '@angular/http';

import 'rxjs/add/operator/toPromise';

import {GraphData} from './graph-data';

@Injectable
export class GraphDataService {
    private dataApiUrl = 'app/graph-data';

    constructor(private http: Http) {}

    getGraphData() : Promise<GraphData[]> {
        return this.http.get(this.dataApiUrl)
            .toPromise()
            .then(response => response.json().data as GraphData[])
            .catch(this.handleError);
    }

    private handleError(error: any): Promise<any> {
        console.error('an error occurred', error); // only for demo
        return Promise.reject(error.message || error);
    }
}

Error compiling in js:

app/graph-data.service.ts(11,1): error TS1238: Unable to resolve signature of class decorator when called as an expression.
  Supplied parameters do not match any signature of call target.
+4
source share
1 answer

Your decorator should look like this:

@Injectable()

Brackets needed

+10
source

Source: https://habr.com/ru/post/1657971/


All Articles