基于Angularjs-router动态改变Title值的问题

许久没写Angularjs这玩意儿了,发现以前项目直接从dom元素去修改title实属简陋了些。

懒得废话,上代码

index里面直接即可。</p> <p>路由<a href="https://www.jb51.cc/tag/wenjian/" target="_blank" class="keywords">文件</a>我作名con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a></p> <div class="jb51code"> <pre class="b<a href="https://www.jb51.cc/tag/rush/" target="_blank" class="keywords">rush</a>:js;"> app.run(['$rootS<a href="https://www.jb51.cc/tag/cop/" target="_blank" class="keywords">cop</a>e','$log',function($rootS<a href="https://www.jb51.cc/tag/cop/" target="_blank" class="keywords">cop</a>e,$log){ $rootS<a href="https://www.jb51.cc/tag/cop/" target="_blank" class="keywords">cop</a>e.$on('$stateChangeSuccess',function(event,toState,toP<a href="https://www.jb51.cc/tag/ara/" target="_blank" class="keywords">ara</a>ms,fromState,fromP<a href="https://www.jb51.cc/tag/ara/" target="_blank" class="keywords">ara</a>ms){ $rootS<a href="https://www.jb51.cc/tag/cop/" target="_blank" class="keywords">cop</a>e.title = toState.data.title; }); }]);</pre> </div> <p>就是如此简单粗暴,当然$stateProvider.state里面加<a href="https://www.jb51.cc/tag/yige/" target="_blank" class="keywords">一个</a>title参数也是必须的。</p> <p><h3>比如:</h3></p> <div class="jb51code"> <pre class="b<a href="https://www.jb51.cc/tag/rush/" target="_blank" class="keywords">rush</a>:js;"> .state('about',{ url: '/about',templateUrl : 'about.html',title:"我就是我,不一样的烟火" <p>}) </p> </pre> </div> <p>当然不懂的朋友可以找我咨询 ,其实我也有待学习</p> <p><h3>----------------------------------分界线------------------------------------------</h3></p> <p><p class="pic_center"><img src="https://files.jb51.cc/file_images/article/201808/20180830153334.jpg" /></p></p> <p>这data里面就包含title,也可以包含其它很多东西。</p> <p>以上这篇基于Angularjs-router动态改变Title值的问题就是小编<a href="https://www.jb51.cc/tag/fenxiang/" target="_blank" class="keywords">分享</a>给大家的全部<a href="https://www.jb51.cc/tag/neirong/" target="_blank" class="keywords">内容</a>了,希望能给大家<a href="https://www.jb51.cc/tag/yige/" target="_blank" class="keywords">一个</a>参考,也希望大家多多<a href="https://www.jb51.cc/tag/zhichi/" target="_blank" class="keywords">支持</a>编程之家。</p><div class="topcard-tags"><a href="https://m.jb51.cc/tag/router/" class="tag_link" target="_blank">router</a><a href="https://m.jb51.cc/tag/routerp/" class="tag_link" target="_blank">router</a><a href="https://m.jb51.cc/tag/prouter/" class="tag_link" target="_blank">router</a><a href="https://m.jb51.cc/tag/Titlezhi/" class="tag_link" target="_blank">Title值</a></div> </div> </div> </div> <!-- row end--> <div class="clearfix"></div> <!-- row --> <div class="col-sm-12 col-md-12 col-lg-12"> <div class="card"> <div class="title"><h1>相关文章</h1></div><div class="list_con"> <img src="https://m.jb51.cc/res/2024/09-25/18/879e7ec08a36083a57dfc8b44214469d.gif" width="100" height="64" style="float:right;margin-left:20px;" /> <div class="title"> <a href="https://m.jb51.cc/js/4742335.html" title="自定义web弹窗/层:简易风格的msg与可拖放的dialog,生成博客园文章目录弹窗">自定义web弹窗/层:简易风格的msg与可拖放的dialog,生成博客园文章目录弹窗</a> </div> <div class="summary">前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...</div> </div><div class="list_con"> <img src="https://m.jb51.cc/res/2024/09-25/18/84bd76d88488cafdfb2789b5a991fecf.png" width="100" height="64" style="float:right;margin-left:20px;" /> <div class="title"> <a href="https://m.jb51.cc/js/4742334.html" title="nice-validator表单验证插件的简单使用">nice-validator表单验证插件的简单使用</a> </div> <div class="summary">前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...</div> </div><div class="list_con"> <img src="https://m.jb51.cc/res/2024/09-25/18/cf659cff914621d918c6072273c30973.gif" width="100" height="64" style="float:right;margin-left:20px;" /> <div class="title"> <a href="https://m.jb51.cc/js/4742333.html" title="基于“formData批量上传的多种实现” 的多图片预览、上传的多种实现">基于“formData批量上传的多种实现” 的多图片预览、上传的多种实现</a> </div> <div class="summary">前言 图片上传是web项目常见的需求,我基于之前的博客的代码...</div> </div><div class="list_con"> <img src="https://m.jb51.cc/res/2024/09-25/18/02f80db4fdf55f3a24674e2854e018f2.png" width="100" height="64" style="float:right;margin-left:20px;" /> <div class="title"> <a href="https://m.jb51.cc/js/4742332.html" title="踹掉后端,前端导出Excel!">踹掉后端,前端导出Excel!</a> </div> <div class="summary">前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...</div> </div><div class="list_con"> <img src="https://m.jb51.cc/res/2024/09-25/18/db8dce1453ed09a8230451f2a9fcdc68.png" width="100" height="64" style="float:right;margin-left:20px;" /> <div class="title"> <a href="https://m.jb51.cc/js/4742331.html" title="Web Worker——js的多线程,实现统计博客园总阅读量、总评论量、总推荐量">Web Worker——js的多线程,实现统计博客园总阅读量、总评论量、总推荐量</a> </div> <div class="summary">前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...</div> </div><div class="list_con"> <img src="https://m.jb51.cc/res/2024/09-25/18/1cd1c972ce822d1a99b7d1b2c8f9cfcd.png" width="100" height="64" style="float:right;margin-left:20px;" /> <div class="title"> <a href="https://m.jb51.cc/js/4742330.html" title="select标签 禁止选择但又能通过序列化form表单传值到后台">select标签 禁止选择但又能通过序列化form表单传值到后台</a> </div> <div class="summary">前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...</div> </div></div> </div> <!-- row end--> </div> </div> <footer id="footer"> <div class="container"> <div class="copyright"> Copyright © 2018 编程之家. 当前版本 V7.0.16<br> <span class="ml5">编程之家 版权所有 <a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">闽ICP备13020303号-8</a> </div> </div> </footer> <script> (function () { var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(bp, s); })(); </script> <script src="https://m.jb51.cc/js/count.js"></script> </body> </html>