2

With this TypeScript (based on some online course):

interface IProduct {
    productName: string
}

interface IProductResource extends ng.resource.IResource<IProduct> {
}

interface IDataAccessService {
    getProductService(): ng.resource.IResourceClass<IProductResource>
}

class DataAccessService implements IDataAccessService {
    static $inject = ['$resource'];

    constructor(private $resource:ng.resource.IResourceService) {
    }

    getProductService():ng.resource.IResourceClass<IProductResource> {
        return this.$resource("sampleUrl");
    }

}

angular.module('app').service('dataAccessService', DataAccessService);

I have a code that uses dataAccessService:

var obj : IProductResource = dataAccessService.getProductService().get();

obj has all angular's REST helper methods like $save/$delete, but I don't have access to interface obj.productName. What is wrong with this code?

1
  • how to define API actions and their definition? surly i need to define it inside this.$resource("sampleUrl"); , but there should be ts definitions too, how to do that? Commented Jan 26, 2017 at 20:16

1 Answer 1

2

I think I got it. It should be:

interface IProductResource
    extends ng.resource.IResource<IProduct>, IProduct {
}

Any comments on that?

Thanks!

Sign up to request clarification or add additional context in comments.

1 Comment

That is what I did

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.