脚本宝典收集整理的这篇文章主要介绍了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>
以上是脚本宝典为你收集整理的Angular单页面动态修改title[兼容微信]全部内容,希望文章能够帮你解决Angular单页面动态修改title[兼容微信]所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。