var app = angular.module('app', ['ngRoute']);
app.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) { $routeProvider .when('/index', {templateUrl: '../tpls/home.html', title: '首頁'}) .otherwise({redirectTo: '/index', title: '首頁'}); }]);
在裏面定義run ,經過監聽 $routeChangeSuccess
的變化來動態調用標題html
app.run(['$rootScope', function ($rootScope) { $rootScope.$on('$routeChangeSuccess', function (event, current, previous) { $rootScope.title = current.$$route.title || '首頁'; document.title = current.$$route.title || '首頁'; var $body = angular.element('body'); var $iframe = $('<iframe src="../image/arrow.png" style="display: none"></iframe>').on('load', function () { $timeout(function () { $iframe.off('load').remove(); }, 0); }).appendTo($body); });
在html裏同過頭部head裏的title
動態調用titleapp
<head> <title ng-bind="title">首頁</title> </head>