0

I am trying to make http call from my ionic app to return some json data. But it shows the error:

[$injector:nomod] Module '$http' is not available!

I think I have to add the module http to Angularjs. Please let me know how to add a new module like http to ionic framework. Thanks.

4
  • Show your code please ? Commented Aug 24, 2015 at 5:36
  • $http.post('/someUrl', {msg:'hello word!'}). then(function(response) { // this callback will be called asynchronously // when the response is available }, function(response) { // called asynchronously if an error occurs // or server returns response with an error status. }); Commented Aug 24, 2015 at 5:38
  • angular.module('starter.controllers', []) // A simple controller that fetches a list of data from a service .controller('PetIndexCtrl', function($scope, PetService) { // "Pets" is a service returning mock data (services.js) $scope.pets = PetService.all(); }) // A simple controller that shows a tapped item's data .controller('PetDetailCtrl', function($scope, $stateParams, PetService) { // "Pets" is a service returning mock data (services.js) $scope.pet = PetService.get($stateParams.petId); }); Commented Aug 24, 2015 at 5:41
  • Yes. @evc is right. See his answer. Commented Aug 24, 2015 at 5:46

1 Answer 1

2

$http is not module, it's a service, which is injected like this

angular.module('app').controller('TestController', function($scope, $http){
    //use $http here
    $http.get('https://stackoverflow.com').then(function(successResponse){
       $scope.data = successResponse;
    }, function(errorRepsonse){
       $scope.error = errorRepsonse;
    });
});

Docs

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.