Ibek Ibek - 3 months ago 17
TypeScript Question

Angular/Typescript, this.$resource is not a function

I'm getting a TypeError: this.$resource is not a function. This is my code

export class DataAccessService
implements IDataAccessService {

static $inject = ["$resource"];
constructor(private $resource: ng.resource.IResourceService) {
}

getTravelExpenseType(): ng.resource.IResourceClass<T> {
return this.$resource('URL:id', {}, {});
}
}

common.service("dataAccessService",
[DataAccessService]);

Answer
common.service("dataAccessService",
    [DataAccessService]);

The problem is that you're passing an array as your service definition. When you do that, you're supposed to list the dependencies to inject in the array first, and your constructor as the last element. Since you're not listing any dependencies to inject, nothing gets injected.

Just get rid of the array:

common.service("dataAccessService", DataAccessService);
Comments