本文介绍了与AngularJS +幻影的Open Graph的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行 AJAX应用程序的安装,并且使用的并href=\"https://github.com/steeve/angular-seo\" rel=\"nofollow\">角SEO的的一个问题, BU没有收到任何的关注在开发者社区。

This seems to be an issue that concerns many users, bu has received no attention whatsoever at the developers community.

meta标签,这是我必须提到,无不充斥着来自测试,我已经进行的当前信息的我

My of meta tags, which I must mention that are all filled with the current information from test that I've conducted:

  <meta property="og:type" content="website">
  <meta property="og:title" content="{{model.title}}" />
  <meta property="og:description" content="{{layout.og.description()}}" />
  <meta property="og:image" content="{{layout.og.image()}}" />
  <meta property="og:url" content="{{layout.og.currentUrl()}}" />

这可能是什么问题。

What could be the problem

推荐答案

如果您检查那些meta标签,甚至在角运行时,其内容属性为这样的...不像NG-绑定或东西,将取代在运行时。为了规避这个问题,我创建了以下指令:

If you Inspect those meta tags, even while angular is running, the content attribute is left like that... unlike a ng-bind or something that will replace at runtime. To circumvent this, I created the following directive:

angular
  .module('app')
  .directive('ngContent', [
    function() {
      return {
        link: function($scope, $el, $attrs) {
                $scope.$watch($attrs.ngContent, function(value) {
                  $el.attr('content', value);
                });
              }
      };
    }
  ])
;

如果是,以下面的方式实现的:

Then implemented in the following manner:

<meta property="og:description" ng-content="myDescriptionFunction()" />

这将在meta标签创建一个干净的内容=这里的一些说明。属性的内容是动态变化的。(观看铬督察的元素您浏览),似乎为我工作!

This will create a clean content="Some description here." attribute in the meta tag as that content dynamically changes... (watch the element in chrome inspector as you browse) seems to work for me!

这篇关于与AngularJS +幻影的Open Graph的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 09:23