S
S
Sergey2015-12-29 14:04:57
JavaScript
Sergey, 2015-12-29 14:04:57

Error using service in your service?

angular.module('cool')
.provider('AllComment', function ($http) {
  var ctrl = 'AllCommentCtrl';
  return {
    setCtrl: function (data) {
      ctrl = data;
      return this;
    },
    $get: function () {
      console.log(ctrl);
    }
  }
});

Throws Uncaught Error: [$injector: modulerr
] Failed to instantiate module cool due to:
Error: [$injector:unpr] Unknown provider: $http
How to add a service?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zakharov Alexander, 2015-12-29
@Sergamers

Update: It's wrong to edit the code this way. See: stackoverflow.com/questions/17497006/use-http-insi...
Correct the code a bit:

angular.module('cool')
.provider('AllComment', ["$http", function ($http) {
  var ctrl = 'AllCommentCtrl';
  return {
    setCtrl: function (data) {
      ctrl = data;
      return this;
    },
    $get: function () {
      console.log(ctrl);
    }
  }
}]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question