0

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.

crazyhor77
  • 155
  • 2
  • 12
  • I'm not really familiar with the supersonic framework, but both errors would suggest that the source code that provides supersonic and I'm guessing jquery is not available in the context that the code runs. So first guess would be that this is some kind of initialization problem. Do you need to establish which libraries specifically to use, or does supersonic take care of that for you? – orbitbot Mar 30 '15 at 23:12
  • 1
    It looks like you might be missing an injection into your `module`. Also, you appear to be using a mix of angular and JQuery here, you may want to look into the "angular way" to access data, `$('#username')` is JQuery. – Claies Mar 30 '15 at 23:13
  • more than likely, the order of the scripts in your HTML page is wrong; can you post the portion of your page where you are loading your scripts for review? – Claies Mar 30 '15 at 23:17
  • It works in my project with this structure: `.controller('IndexController', function($scope, supersonic, $http) { });` using `AngularJS v1.3.15`, `steroids-js - v3.5.10`, and `supersonic 1.2.0`. What versions of the code are you using? I've been seeing reports of lots of Angular error messages in the console on new builds. It could be a temporary issue. – area28 Mar 30 '15 at 23:49
  • you guys were spot on with the jquery, i was so focused on the injection, i forgot about the jquery selectors. i have fixed that and can inject $http, but i can't inject both $http and supersonic. if i try the code from area28 post, i still get unknown provider: supersonicProvider. i am using angularjs v1.3.15 and steroids-js v3.5.10 and supersonic 1.1.2. the same except supersonic, ill update that and see what happens. – crazyhor77 Mar 31 '15 at 21:22
  • ok, updated to 1.2.1, same result :( – crazyhor77 Mar 31 '15 at 21:26

1 Answers1

2

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) {
});
crazyhor77
  • 155
  • 2
  • 12