简体   繁体   中英

Can not Inject Service into Controller

I wrote a service (empty, just for testing purposes), which I want to inject into a controller.

However, this is unfortunately not working, I can't see the Problem.

Here is my code:

app.controller('AppCtrl', function($scope, $location, Test){

  $scope.goto = function(destination){
    $location.path(destination);
  }

})

app.service('Test', ['', function(){

}])

And here is the Exception:

Error: [$injector:unpr] Unknown provider: Provider <-  <- Test
http://errors.angularjs.org/1.3.13/$injector/unpr?p0=Provider%20%3C-%20%20%3C-%20Test
    at REGEX_STRING_REGEXP (ionic.bundle.js:8890)
    at ionic.bundle.js:12824
    at Object.getService [as get] (ionic.bundle.js:12971)
    at ionic.bundle.js:12829
    at getService (ionic.bundle.js:12971)
    at invoke (ionic.bundle.js:13003)
    at Object.instantiate (ionic.bundle.js:13020)
    at Object.<anonymous> (ionic.bundle.js:12881)
    at Object.invoke (ionic.bundle.js:13012)
    at Object.enforcedReturnValue [as $get] (ionic.bundle.js:12865)

I can't figure out the problem

You're injecting a dependency of '' so Angular is telling you it can't find that provider.

Instead, simply:

app.service('Test', function(){

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM