[英]Angularjs 1.5 ng-controller on the <head> tag
I'm using Angularjs 1.5. 我正在使用Angularjs 1.5。
Created a service to handle a META data and page title. 创建了一个服务来处理META数据和页面标题。 trying to apply it. 尝试应用它。
The issue is - for some reason if i define a controller directly on the <head>
tag: 问题是-由于某种原因,如果我直接在<head>
标记上定义控制器:
<head ng-controller="headMetaController">
the controller will not be loaded at all, but if i wrap it in additional <div>
withing the <head>
: 控制器将不会被加载,但是如果我将其与<head>
包装在其他<div>
<head>
:
<head>
<div ng-controller="headMetaController">
<title ng-bind="seoMetaService.title()"></title>
<meta name="description" content="{{ seoMetaService.metaDescription() }}">
<meta name="keywords" content="{{ seoMetaService.metaKeywords() }}">
<div>
</head>
=> it works. =>它有效。
So, i guess its somehow connected with particularly <head>
tag => not sure, what is the right way to solve it? 因此,我想它可能与<head>
标签=>有某种联系,不确定,解决它的正确方法是什么? i'm also do afraid that putting the meta data within the additional <div>
may not be a good idea for SEO purposes? 我还担心将元数据放在附加的<div>
可能不是出于SEO目的的好主意?
If you're concerned about SEO, you're going to have to approach this from another angle. 如果您担心SEO,则必须从另一个角度解决这个问题。
In addition to <div>
not being valid inside of <head>
, using interpolation on <meta>
values is a red flag. 除了<div>
不是有效的内部<head>
使用内插<meta>
值是一个红色信号。 The crawlers who care about these tags, won't see them—instead they'll see {{ seoMetaService.metaKeywords()}}
, which is obviously bad for SEO. 关心这些标签的爬虫将不会看到它们,而是会看到{{ seoMetaService.metaKeywords()}}
,这显然对SEO不利。
Solution A: Render these values server side. 解决方案A:在服务器端呈现这些值。
Solution B: Keep what you have, but instruct crawlers to access your page at a different location. 解决方案B:保留现有内容,但指示爬网程序在其他位置访问您的页面。 Add <meta name="fragment" content="!">
, and allow a snapshot of your rendered page to live elsewhere—and be served up when ?_escaped_fragment_=
is added to the URL. 添加<meta name="fragment" content="!">
,并允许将渲染页面的快照保存在其他位置,并在将?_escaped_fragment_=
添加到URL时提供。 You can delegate this part to services like prerender.io or similar, which will scan and store your pages. 您可以将此部分委托给诸如prerender.io或类似服务之类,以扫描和存储您的页面。
First of all, i think <div>
is not a valid tag to be inside of the <head>
tag since the tag is only meant to be for metadata, scripts, styles, and other stuff which isn't meant to be displayed. 首先,我认为<div>
在<head>
标记内不是有效的标记,因为该标记仅用于元数据,脚本,样式和其他不希望显示的内容。
Secondly, even though you call the controller like this it doesn't mean you can access controller variables inside head
tag. 其次,即使您这样调用控制器,也并不意味着您可以访问head
标记内的控制器变量。 Only service/factories can invoke inside head
tag. 只有服务/工厂可以调用内部head
标签。
So instead of calling it from head
tag call the controller from html
tag or body
tag or inside body tag 因此,与其从head
标签调用它, head
从html
标签或body
标签或body标签内部调用控制器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.