Error: inject Angular $http service into requires plugin

I want to use AngularJS $http service in my custom requireJS plugin. The following is my code.

I can see angular module in my plugin "foo", but I don't know how to get $http service from the angular module.

Could anybody give me some direction? Thx in advance.

main.js

require.config({
    waitSeconds : 20, //make sure it is enough to load all scripts
    paths: {
        cordova: '../lib/js/ng-cordova',
        angular: '../lib/js/angular/angular',                   // <---- here is angular
        angularAnimate: '../lib/js/angular/angular-animate',
        angularTouch: '../lib/js/angular/angular-touch',
        angularSanitize: '../lib/js/angular/angular-sanitize',
        uiRouter: '../lib/js/angular-ui/angular-ui-router',
        ionic: '../lib/js/ionic.bundle',
        ionicServiceCore: '../lib/js/ionic-core',
        angularIonic: '../lib/js/ionic-angular'
      }
}

foo.js

define(['angular'],function(angular){

  return {
    load: function(name,req,onLoad,config){
      console.log(angular);
      // 
      // I want to use $http here
      // but how to retrieve $http from angular module???
      // 
    } // load
  };

});

Answers


You should be able to get $http service with this code:

define(['angular'], function(angular) {

  return {
    load: function(name, req, onLoad, config) {
        var $http = angular.injector(['ng']).get('$http');
        // $http.get(...).then(...)
    }
  };

});

Need Your Help

How to authenticate user ? (Android/Java/Symfony)

java android security symfony

I'm developping an Android App that need authentication. However, there an existing web application (using Symfony) with accounts, and I have to reuse the same accounts to authenticate my users.

Cryptic warning without any google results [In Simulator]

iphone ios xcode ios7 state-restoration

I get this warning in my iOS project: (iOS7, XCode 5 GM)