0

I am using $http.get. All injections seems to be in place but I am getting error: TypeError: Cannot read property 'get' of undefined.

UPDATED

app.controller("MyCtrl", ['$scope', '$state', '$http', function ($scope, $state, $http) {
        $scope.getEntryStateUrl = function(apiUrl){
            $http.get(apiUrl).success(function(data){/*...*/}));

    }

}

UPDATE:

Thanks for pointing out about success and injection. Now I am facing this problem.

Community
  • 1
  • 1
J.Olufsen
  • 13,415
  • 44
  • 120
  • 185
  • You have an injector mistake in your syntax. $scope is followed by $stateprovider in your function, but not your injector. You need to inject $stateProvider. – Blunderfest Feb 03 '15 at 22:49

3 Answers3

2

You're injecting $state and trying to use $stateProvider as a parameter of the success callback? The success method of $http automaticly assigns the parameters of success:

success(function(data, status, headers, config){});

So when you're doing this:

success(function(data, $stateProvider){});

You're assigning the status object returned by the $http call to variable $stateProvider. See: https://docs.angularjs.org/api/ng/service/$http

Also you've got an extra parenthesis ) at the end of your success method:

$http.get(apiUrl).success(function(data){/*...*/}));

Should be:

$http.get(apiUrl).success(function(data){/*...*/});

It would help if you actually mentioned in your question what you are trying to accomplish.

iH8
  • 27,722
  • 4
  • 67
  • 76
0

Check the variable names that you are declaring before the controller function. You are missing $stateProvider

app.controller("MyCtrl", ['$scope', '$state', '$http', function ($scope, $state, $http) {
Stefano Dalpiaz
  • 1,673
  • 10
  • 11
  • Now I am getting `Error: [$injector:unpr] Unknown provider: $stateProviderProvider <- $stateProvider` – J.Olufsen Feb 03 '15 at 22:53
  • http://stackoverflow.com/questions/23931040/how-inject-stateprovider-in-angular-application – J.Olufsen Feb 03 '15 at 22:55
  • If you are not using that variable anywhere in your controller, simply remove both the string and the function argument called `$stateProvider`. If you do need it, make sure that you are referencing ui-router when you create your Angular module. – Stefano Dalpiaz Feb 03 '15 at 22:56
  • .. and thanks for your link. I overlooked the fact that your variable needs to be called $state instead of $stateProvider, updating my answer. – Stefano Dalpiaz Feb 03 '15 at 22:59
0

Your function receives inputUrl but you pass apiUrl to $http.get

Ninjarabbi
  • 480
  • 2
  • 15