javascript - module详解 - angular module.run ReferenceError:$ location没有被定义




angularjs module config (2)

我想要AngularJS没有重新加载的路径,请看http://joelsaupe.com/programming/angularjs-change-path-without-reloading/

在core.js中:

 'use strict';
    angular.module('App',['ngRoute'])
        .run(['$route', '$rootScope', '$location', function ($route, $rootScope, $location) {
        var original = $location.path;
        $location.path = function (path, reload) {
            if (reload === false) {
                var lastRoute = $route.current;
                var un = $rootScope.$on('$locationChangeSuccess', function () {
                    $route.current = lastRoute;
                    un();
                });
            }
            return original.apply($location, [path]);
        };
    }]);

在控制器中:

    angular.module('App')        
        .controller('DetailController', ['$scope', '$location',  function($scope) {
  $scope.changeURL = function(){
            console.log("IN changeURL");
            $location.path('/sample/gfshdfdsf', false);
        };      
    }]);

如果调用changeURL,将发生错误: ReferenceError: $location is not defined

有人可以帮我吗? 谢谢!

https://code.i-harness.com


$ location不是注入controller ,所以只需要改变

.controller('DetailController', ['$scope', '$location',  function($scope)

.controller('DetailController', ['$scope', '$location',  function($scope, $location)

我得到了同样的错误,我从定义中删除了$ rootScope。 之后,它的工作。 不知道为什么。

不工作

app.factory("OrganizationService",   
    ['$q', '$http', '$log', '$location', '$rootScope', '$timeout', 'LoadSubscriptionsService', 'LoadRolesService',
  function($scope , $http, $log, $location, $cookies, $rootScope, $timeout) {

加工

app.factory("OrganizationService",   
    ['$q', '$http', '$log', '$location', '$timeout', 'LoadSubscriptionsService', 'LoadRolesService',
  function($scope , $http, $log, $location, $cookies, $timeout) {




url-rewriting