如何更新metajs中的元标记?

前端之家收集整理的这篇文章主要介绍了如何更新metajs中的元标记?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用angularjs开发应用程序。我想在路由更改上更新元标记
如何更新可以在页面的“查看源代码”中显示的angularjs中的元标记

这里是一个HTML代码

  1. <!DOCTYPE html>
  2. <html ng-app="app">
  3. <head>
  4. <Meta name="viewport" content="width=device-width,initial-scale=1.0">
  5. <Meta name="fragment" content="!" />
  6. <Meta name="title" content="Test App">
  7. <Meta name="description" content="Test App">
  8. <Meta name="keywords" content="Test,App">
  9.  
  10. <link rel="stylesheet" href="css/jquery-ui-1.10.2.custom.min.css" />
  11. <link rel="stylesheet" href="css/extra.css" />
  12. <script src="js/libs/jquery-1.8.3.min.js"></script>
  13. <script src="js/libs/jquery-ui-1.10.2.custom.min.js"></script>
  14. <script src="js/libs/angular.min.js"></script>
  15. <script src="js/controller.js"></script>
  16. <script src="js/routes.js"></script>
  17. </head>
  18. <body>
  19. <div ng-controller="mainCtrl" class="main-container" loading>
  20. <div class="container-holder">
  21. <div class="container">
  22. <div ng-include src='"elements/header.html"'></div>
  23. <div ng-view class="clearfix"></div>
  24. </div>
  25. </div>
  26.  
  27. <div ng-controller="userCtrl" id="test">
  28. <div class="container" class="login-container">
  29. <div id="login-logo">
  30. <img src="images/logo-300.png" alt="" class="login-img"/>
  31. <br />
  32. <div ng-view></div>
  33. </div>
  34. </div>
  35. </div>
  36. </body>
  37. </html>
  1. <html ng-app="app">
  2. <title ng-bind="Metaservice.MetaTitle()">Test</title>
  3. <Meta name="description" content="{{ Metaservice.MetaDescription() }}" />
  4. <Meta name="keywords" content="{{ Metaservice.MetaKeywords() }}" />
  5.  
  6.  
  7. <script>
  8. var app = angular.module('app',[]);
  9. app.service('MetaService',function() {
  10. var title = 'Web App';
  11. var MetaDescription = '';
  12. var MetaKeywords = '';
  13. return {
  14. set: function(newTitle,newMetaDescription,newKeywords) {
  15. MetaKeywords = newKeywords;
  16. MetaDescription = newMetaDescription;
  17. title = newTitle;
  18. },MetaTitle: function(){ return title; },MetaDescription: function() { return MetaDescription; },MetaKeywords: function() { return MetaKeywords; }
  19. }
  20. });
  21.  
  22. app.controller('myCtrl',function($scope,$rootScope,MetaService){
  23. $rootScope.Metaservice = MetaService;
  24. $rootScope.Metaservice.set("Web App","desc","blah blah");
  25. });
  26. </script>
  27. <body ng-controller="myCtrl"></body>
  28.  
  29.  
  30. </html>

猜你在找的Angularjs相关文章