angularjsappgyversupersonic

using $http in supersonic controller


About to move on from this framework which I don't want to do as it looks great, but facing one headache after another in my early stages.

Currently, my problem is trying to make a $http call from a controller. Here is my current code:

angular
  .module('login', [])
  .controller('LoginController', ['$scope', '$http', 'supersonic', function($scope, $http, supersonic) {
      // Controller functionality here
      $scope.login = function () {
          supersonic.logger.debug('before ajax');

          $http.post('http://server/api/user/login', {
              username: $('#username').val(),
              password: $('#password').val()
          }).error(function () {
              console.log('error');
              supersonic.logger.debug('Error');
          }).success(function () {
              console.log('success');
              supersonic.logger.debug('Success');
          });

          supersonic.logger.debug('after ajax');
      }
  }]);

I admit I'm new to this, but I've read a lot of documentation and trawled the internet trying different ways to inject $http etc with no luck. This code will result in an error, "unknown provider: supersonicProvider".

If I exclude supersonic from the injection, then the supersonic parameter is undefined.

Even if I exclude the supersonic injection and comment out the supersonic.logger lines, the $http line generates an error of "$ is not defined".

Getting these errors from the chrome debugger through usb if that makes any difference.

Appreciate any help on this one.


Solution

  • the following code seems to do the trick, gives me access to $http and supersonic in the controller

    angular
    .module('login', ['supersonic'])
    .controller('LoginController', function($scope, supersonic, $http) {
    });