欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Angularjs 动态改变title标题(兼容ios)

程序员文章站 2022-05-12 13:29:13
废话不多说了,直接给大家贴代码了,具体代码如下所示:
angular.modu...

废话不多说了,直接给大家贴代码了,具体代码如下所示:

<pre name="code" class="javascript">angular.module('myapp.loginctrl', []) 
  .config(function($httpprovider) { 
    $httpprovider.defaults.headers.post['content-type']='application/x-www-form-urlencoded;charset=utf-8'; 
//改变header中content-type的格式 
  }) 
.controller('loginctrl',['$scope','$http',function($scope,$http){}]) 
//兼容ios动态改变title标题 
.run(['$location','$rootscope',function($location, $rootscope){  
  $rootscope.$on('$statechangesuccess', function (event, tostate, toparams, fromstate, fromparams) {  
   $rootscope.title = tostate.title  
  });  
  $rootscope.$watch('title',function(title){ 
    var body = document.getelementsbytagname('body')[0]; 
    document.title = title; 
    var iframe = document.createelement("iframe"); 
    iframe.title = '登陆'; 
    iframe.width = 0; 
    iframe.height = 0; 
    iframe.src = '//m.baidu.com/favicon.ico'; 
    iframe.style.display = 'none'; 
    iframe.addeventlistener('load', function() { 
      settimeout(function() { 
        // iframe.removeeventlistener('load'); 
        document.body.removechild(iframe); 
      }, 0); 
    }); 
    document.body.appendchild(iframe); 
  }); 
}]); </pre><br> 
<br> 
<pre></pre> 
<pre code_snippet_id="2083087" snippet_file_name="blog_20161229_4_8475823" name="code" class="javascript">//路由<pre name="code" class="javascript">  .state('deliciousfood',{ 
   title:'美食住宿', 
   url:'/deliciousfood', 
   templateurl:'/hq/views/deliciousfood/deliciousfood.html', 
   controller:'deliciousfoodctrl', 
   resolve:{ 
    loadmyctrl:['$oclazyload',function($oclazyload){ 
     return $oclazyload.load([ 
      '/hq/views/deliciousfood/deliciousfoodctrl.js', 
      ]).then(function(){}) 
    }] 
   }  
  })</pre><br> 
<pre></pre> 
<br> 
</pre> 

以上所述是小编给大家介绍的angularjs 动态改变title标题(兼容ios),希望对大家有所帮助