1

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]);
4
  • are you loading your dependency angular-resource.js ? <script src="path/to/angular-resource.js"></script> Commented Aug 11, 2016 at 8:46
  • How do you use getTravelExpenseType method? Commented Aug 11, 2016 at 8:47
  • @Arno_Geismar Yes, I'm loading the angular-resource.js in index.html Commented Aug 11, 2016 at 8:52
  • @dsfq var traveExpenseTypeResource = dataAccessService.getTravelExpenseType(); traveExpenseTypeResource.query((data) => { this.travelExpenseTypes = data; }); Commented Aug 11, 2016 at 8:54

1 Answer 1

1
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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.