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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值