Angular单页面动态修改title[兼容微信]
发布时间:2020-12-17 09:20:09 所属栏目:安全 来源:网络整理
导读:js文件 定义module var app = angular.module('app',['ngRoute']); 在config通过路由定义标题 app.config(['$routeProvider','$locationProvider',function ($routeProvider,$locationProvider) { $routeProvider .when('/index',{templateUrl: '../tpls/hom
js文件定义modulevar 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,通过监听 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里的 <head> <title ng-bind="title">首页</title> </head> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |