2016-09-26 5 views
0

ロケーションサービスを使いたいのですが、サービスを注入するとエラーが未定義になります。私は$locationサービス未定義の取得理由

angular.js:4587 Uncaught Error: [$injector:modulerr] Failed to instantiate module dashboard due to: 
Error: [$injector:modulerr] Failed to instantiate module sites due to: 
Error: [$injector:modulerr] Failed to instantiate module workPlan due to: 
Error: [$injector:unpr] Unknown provider: $location 
http://errors.angularjs.org/1.5.5/$injector/unpr?p0=%24location 
    at http://localhost/Playground/Scripts/angular.js:68:12 
    at http://localhost/Playground/Scripts/angular.js:4458:19 

任意のアイデア:

(function() { 
     "use strict"; 

     angular.module("workPlan", ['ui.router', 
             'geomindCommon', 
             'templates', 
             'lookups', 
             "ngAnimate", 
             'ngTouch', 
             'ui.grid', 
             'ui.grid.expandable', 
             'ui.grid.selection', 
             'ui.grid.pinning', 
             'ui.grid.resizeColumns', 
             'ui.bootstrap', 
             'damageEvent']) 

      .config([ 
        "$location", 
        "$stateProvider", 
        "$urlRouterProvider", 
        function ($location, $stateProvider, $urlRouterProvider) { 

         $urlRouterProvider.otherwise("/MainPage"); 
         $urlRouterProvider.when('/MainPage/onDevice', '/sites/list');//if request comes from device 
         $urlRouterProvider.when('/MainPage/inspectorArea', '/inspectorArea'); 
        //var absUrl = $location.absUrl(); 

      } 
    ]); 

--Updated--

私が手にコンソールでエラー:ここ

はangularjsコードですか?

+6

'$ location'はサービスです。 '.config'メソッドの間にプロバイダ(と定数)しか利用できません – Phil

+0

$ locationProviderを使用します – Tommy

+0

@NexusDuck私は質問を更新しました – Michael

答えて

1

不明プロバイダは:$location

あなたはコンフィグに直接サービスを注入することはできません。使用$locationProvider

+0

$ locationProviderを使用してパスを取得するにはどうすればよいですか? – Michael

+0

$ urlRouterProvider.rule(関数($ injector、$ location){/ *コードはここに* /})を使用してください。あなたの設定で。何をしたいですか? –

+0

$ urlRouterProvider.ruleは、URLが変更されたときにURLを変更するために使用されます。 –

1

構成ブロックにprovidersconstantsしか注入できません。 $location以来

angular.module('aop', []). 
config(function(injectables) { 
    //the injectables here should be provider or constants. $locationProvider 
}). 
run(function(injectables) { 
    //the injectables here can be instance... ie.. $location service. 
}); 
1

それはあなたのconfigブロックで使用できなくなりますサービスです。代わりに$locationProviderを使用します。

.config(['$locationProvider', .. 

それは使用することができるよう、あなたが、runブロックに関連するコードを移動することを検討して、$locationを使用したいならば:

.run(['$location', .. 
-2

関数内の$場所を追加してみてください

(function ($location) { 
+0

彼はすでにこれを行っていますが、サービスはconfigブロックで使用できないため動作しません。 -1 –

関連する問題