angularjs 和 yeoman 的当前位置

Current location with angularjs and yeoman

我已经定义了我的模块的配置:

angular
  .module('myApp', [
    'ngAnimate',
    'ngCookies',
    'ngResource',
    'ngRoute',
    'ngSanitize',
    'ngTouch'
  ])
  .config(function ($routeProvider) {
    $routeProvider

      .when('/models', {
        templateUrl: 'views/models.html',
        controller: 'ModelsCtrl',
        controllerAs: 'models'
      })
      .when('/contacts', {
        templateUrl: 'views/contacts.html',
        controller: 'ContactsCtrl',
        controllerAs: 'contacts'
      })
      .when('/constructor', {
        templateUrl: 'views/constructor.html',
        controller: 'ConstructorCtrl',
        controllerAs: 'constructor'
      })
      .otherwise({
        redirectTo: '/constructor'
      });
  });

是否可以在不使用 angular-ui-router 的情况下获取有关当前用户状态的信息?

您可以注入 $location 服务并使用它的 path() 函数。 这是文档的 link 位置 $location

   angular.module('app')
  .run(['$rootScope','$location', 
function($rootScope, $location) {
    $rootScope.$on('$routeChangeSuccess', function(e, current) {
      console.log('Current route name: ' + $location.path());
    }
  }]);