为什么$ location服务未定义? [英] Why $location service undefined?

查看:84
本文介绍了为什么$ location服务未定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用位置服务,但是在注入服务时出现未定义的错误.

I want to use location service but I get error undefined when I inject the service.

这是angularjs代码:

Here is angularjs code:

(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();

             }
    ]);

-已更新-

我得到的控制台错误:

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

有人知道为什么我未定义 $ location 服务吗?

Any idea why I get $location service undefined?

推荐答案

未知提供者: $ location

您不能将服务直接注入到配置中.使用 $ locationProvider

You can't inject service directly into config. Use $locationProvider

这篇关于为什么$ location服务未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆