Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angularjs – 头部的角度动态元标记大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要在角度应用程序中的特定页面上插入开放图形元标记.

这些标签根据页面的新闻或视频而有所不同.

我尝试在$rootscope中添加一个变量.当变量相关时,将使用元标记填充此变量.

在这是我的问题.只要此变量填充了HTML字符串,它们就不会形成头部的一部分而是输出到正文.我搜索了一天,找不到任何可行的解决方案.任何帮助,将不胜感激

@L_944_12@

我创建了一个 Angular module,可以使用$routeProvider路由定义动态设置元标记.

angular.module('YourApp','ngMeta')
.config(function ($routeProvider,ngMetaProvider) {

  $routeProvider
  .when('/home',{
    templateUrl: 'home-template.html',Meta: {
      //Sets 'Home Page' as the title when /home is open
      title: 'Home page',description: 'This is the description of the home page!'
    }
  })
  .when('/login',{
    templateUrl: 'login-template.html',Meta: {
      //Sets 'Login Page' as the title when /login is open
      title: 'Login page',description: 'Login to this wonderful website!'
    }
  })
});

然后,您可以像这样在HTML中设置元标记

<title ng-bind="ngMeta.title"></title>
<!-- OR <title>{{ngMeta.titlE}}</title> -->    

<!-- This Meta tag can be set using ngMetaProvider -->
<Meta property="og:type" content="{{ngMeta.ogTypE}}" />

<!-- Default locale is en_US -->
<Meta property="og:locale" content="{{ngMeta.ogLocalE}}" />

<!-- This Meta tag changes based on the Meta object of each route -->
<!-- or when the setDescription function is called -->
<Meta name="description" content="{{ngMeta.description}}" />

要动态设置标题,描述和og:图像,可以将ngMeta注入控制器

.controller('DemoCtrl',function(ngMeta) {

    ngMeta.settitle('Demo page');
    ngMeta.setDescription('This is the description of the demo page');
    ngMeta.setOgimgurl('http://example.com/abc.jpg');
});

支持更多标签和ui-router正在开发中.

大佬总结

以上是大佬教程为你收集整理的angularjs – 头部的角度动态元标记全部内容,希望文章能够帮你解决angularjs – 头部的角度动态元标记所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。