如何更新metajs中的元标记?

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

这里是一个HTML代码

<!DOCTYPE html>
    <html ng-app="app">
        <head>
            <Meta name="viewport" content="width=device-width,initial-scale=1.0">
            <Meta name="fragment" content="!" />
            <Meta name="title" content="Test App">
            <Meta name="description" content="Test App">
            <Meta name="keywords" content="Test,App">

            <link rel="stylesheet" href="css/jquery-ui-1.10.2.custom.min.css" />
            <link rel="stylesheet" href="css/extra.css" />
            <script src="js/libs/jquery-1.8.3.min.js"></script>
            <script src="js/libs/jquery-ui-1.10.2.custom.min.js"></script>
            <script src="js/libs/angular.min.js"></script>
            <script src="js/controller.js"></script>
            <script src="js/routes.js"></script>
        </head>
        <body>
            <div ng-controller="mainCtrl" class="main-container" loading>
                <div class="container-holder">
                    <div class="container">
                        <div ng-include src='"elements/header.html"'></div>
                        <div ng-view class="clearfix"></div>
                    </div>
                </div>

                <div ng-controller="userCtrl" id="test">
                    <div class="container" class="login-container">
                        <div id="login-logo">
                            <img src="images/logo-300.png" alt="" class="login-img"/>
                            <br />
                            <div ng-view></div>
                        </div>
                    </div>
                </div>
        </body>
    </html>
<html ng-app="app">
    <title ng-bind="Metaservice.MetaTitle()">Test</title>
    <Meta name="description" content="{{ Metaservice.MetaDescription() }}" />
    <Meta name="keywords" content="{{ Metaservice.MetaKeywords() }}" />


<script>
    var app = angular.module('app',[]);
    app.service('MetaService',function() {
       var title = 'Web App';
       var MetaDescription = '';
       var MetaKeywords = '';
       return {
          set: function(newTitle,newMetaDescription,newKeywords) {
              MetaKeywords = newKeywords;
              MetaDescription = newMetaDescription;
              title = newTitle; 
          },MetaTitle: function(){ return title; },MetaDescription: function() { return MetaDescription; },MetaKeywords: function() { return MetaKeywords; }
       }
    });

   app.controller('myCtrl',function($scope,$rootScope,MetaService){
      $rootScope.Metaservice = MetaService;
      $rootScope.Metaservice.set("Web App","desc","blah blah");
   });
</script>
 <body ng-controller="myCtrl"></body>


</html>
原文链接:https://www.f2er.com/angularjs/145274.html

猜你在找的Angularjs相关文章