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>