Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 Service error. Cannot find cause

I'm pretty new to Angular and have been stuck for some time now. I am trying to make a service that gets data from an internal webapi, it worked before but now it gives an error that i'm unable to solve. Hope one of you guys can help me... The 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);
    }
}

The error it gives while compiling to 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.
like image 711
Saron Grave Avatar asked Dec 25 '22 00:12

Saron Grave


1 Answers

Your decorator should look like:

@Injectable()

Parentheses are required

like image 144
yurzui Avatar answered Dec 28 '22 10:12

yurzui