无法将服务注入控制器

Mar*_*ler 1 javascript angularjs ionic

我写了一个服务(空的,仅用于测试目的),我想将其注入控制器.

但是,遗憾的是这不起作用,我看不出问题.

这是我的代码:

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

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

})

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

}])
Run Code Online (Sandbox Code Playgroud)

这是例外:

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)
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚这个问题

juc*_*uco 6

你注入了一个依赖,''因此Angular告诉你它找不到那个提供者.

相反,简单地说:

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

});
Run Code Online (Sandbox Code Playgroud)