Angular单页面动态修改title[兼容微信]
文章目录
js文件
定义module
var app = angular.module('app', ['ngRoute']);
在config通过路由定义标题
app.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$routeProvider
.when('/index', {templateUrl: '../tpls/home.html', title: '首页'})
.otherwise({redirectTo: '/index', title: '首页'});
}]);
通过run动态调用标题
在里面定义run ,通过监听 $routeChangeSuccess的变化来动态调用标题
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 文件
在html里同过头部head里的title 动态调用title
<head>
<title ng-bind="title">首页</title>
</head>
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论