如何在一个控制器中更改AngularJS路由中的页面URL?

如何在一个控制器中更改AngularJS路由中的页面URL?,angularjs,angular-routing,Angularjs,Angular Routing,这是路由配置: tapp.config(function ($routeProvider) { $routeProvider.when('/', { title: 'Home', controller: 'tCtrlr', templateUrl: '../HTML/Index.html', }), $routeProvider.when('/Tasks', { title: 'Tasks',

这是路由配置:

tapp.config(function ($routeProvider) {
    $routeProvider.when('/', {
        title: 'Home',
        controller: 'tCtrlr',
        templateUrl: '../HTML/Index.html',
    }),
    $routeProvider.when('/Tasks', {
        title: 'Tasks',
        controller: 'tCtrlr',
        templateUrl: '../HTML/Tasks.html',
    }),
    $routeProvider.when('/MyTasks', {
        title: 'My Tasks',
        controller: 'tCtrlr',
        templateUrl: '../HTML/MyTasks.html',
    })

当在页面之间导航时,未设置
标题
,我已经阅读了一些关于此问题的SO线程,但大多数人认为我每个页面都有一个控制器。因此,如何在
when
函数中获得
title
属性?

我的方法非常简单。在管线配置中,您可以定义标题:

.when('/dashboard', {
  title : 'My Dashboard',
  templateUrl : 'templates/sections/app-dashboard.html',
  controller  : 'DashboardController'
})
然后收听$routeChangeSuccess事件,只需设置document.title。在应用程序运行块中(进行此操作的最佳位置)

这种方法的好处是,它允许您避免再次绑定ng bind=“title”

app.run(['$rootScope', '$route', function($rootScope, $route) {
  $rootScope.$on('$routeChangeSuccess', function() {
    document.title = $route.current.title;
  });
}]);