1

I'm trying to use AngularJS (which I'm new to) in combination with TypeScript while following the tutorial. This helped me a lot, but now I ran into the following problem:
I'm using the typing file from DefinitelyTyped which states that each IServiceProvider (which IHttpProvider inherits) has a $get property. While trying to use the $httpProvider service of Angular I need to call the $http.get method (note: without the '$').

When trying to run this it fails because $get is undefined. I tried to change it to get temporarily in the browser and then the code works, so I'm confident that this is the problem. I can't just use get in my TypeScript file, because it would fail to compile.

Now I'd like to know how to work around this problem?

disclaimer: I'm not too comfortable with JavaScript in general either.

1 Answer 1

2

You need to look for IHttpService inorder to use http service. What you are looking at is the Provider recipe of $http ($httpProvider) which is used for global configuration during the .config phase of the application. Instead what you actually inject anywhere else is the instance of $http defined in the $get function of the $httpProvider.

Example usage of both interface definitions:

app.config(['$httpProvider', function($httpProvider:ng.IHttpProvider){...

and

class MyService implements IMyService {
   constructor(private $http:ng.IHttpService){
   }
 //...
}
Sign up to request clarification or add additional context in comments.

1 Comment

Should be app.config(['$httpProvider'], ($httpProvider: ng.IHttpProvider) => { ...

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.