How to dynamically change header based on AngularJS partial view?

后端 未结 22 1971
一向
一向 2020-11-22 10:53

I am using ng-view to include AngularJS partial views, and I want to update the page title and h1 header tags based on the included view. These are out of scope of the parti

22条回答
  •  粉色の甜心
    2020-11-22 11:21

    If you don't have control over title element (like asp.net web form) here is some thing you can use

    var app = angular.module("myApp")
        .config(function ($routeProvider) {
                    $routeProvider.when('/', {
                                                title: 'My Page Title',
                                                controller: 'MyController',
                                                templateUrl: 'view/myView.html'
                                            })
                                .otherwise({ redirectTo: '/' });
        })
        .run(function ($rootScope) {
            $rootScope.$on("$routeChangeSuccess", function (event, currentRoute, previousRoute) {
                document.title = currentRoute.title;
            });
        });
    

提交回复
热议问题