填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

Meta

用于管理 HTML <meta> 标记的服务。

A service for managing HTML <meta> tags.

查看"说明"...

      
      class Meta {
  addTag(tag: MetaDefinition, forceCreation: boolean = false): HTMLMetaElement | null
  addTags(tags: MetaDefinition[], forceCreation: boolean = false): HTMLMetaElement[]
  getTag(attrSelector: string): HTMLMetaElement | null
  getTags(attrSelector: string): HTMLMetaElement[]
  updateTag(tag: MetaDefinition, selector?: string): HTMLMetaElement | null
  removeTag(attrSelector: string): void
  removeTagElement(meta: HTMLMetaElement): void
}
    

参见

Provided in

  •       
          'root'
        

说明

MetaDefinition 对象的属性与 HTML <meta> 标记的属性一一对应。这些标记定义了文档的元数据,这些元数据对于配置内容安全策略、定义浏览器兼容性和安全设置、设置 HTTP 标头、定义用于社交共享的富内容以及搜索引擎优化(SEO)等都很重要。

Properties of the MetaDefinition object match the attributes of the HTML <meta> tag. These tags define document metadata that is important for things like configuring a Content Security Policy, defining browser compatibility and security settings, setting HTTP Headers, defining rich content for social sharing, and Search Engine Optimization (SEO).

要在 document 中标识特定的 <meta> 标签,请使用格式为 "tag_attribute='value string'" 的属性选择字符串。例如,"name='description'"attrSelector 值,与一个 name 属性值为 "description" 的标签匹配。这些选择器可以和 document 的 querySelector() 方法一起使用,格式为 meta[{attrSelector}]

To identify specific <meta> tags in a document, use an attribute selection string in the format "tag_attribute='value string'". For example, an attrSelector value of "name='description'" matches a tag whose name attribute has the value "description". Selectors are used with the querySelector() Document method, in the format meta[{attrSelector}].

方法

在当前 HTML 文档中检索或创建特定的 <meta>。在搜索现有标签时,Angular 会尝试匹配 nameproperty 属性值,并验证所有其他属性值是否相等。如果找到现有元素,则将其返回,并且不会进行任何修改。

Retrieves or creates a specific <meta> tag element in the current HTML document. In searching for an existing tag, Angular attempts to match the name or property attribute values in the provided tag definition, and verifies that all other attribute values are equal. If an existing element is found, it is returned and is not modified in any way.

      
      addTag(tag: MetaDefinition, forceCreation: boolean = false): HTMLMetaElement | null
    
参数
tag MetaDefinition

要匹配或创建的 <meta> 元素定义。

The definition of a <meta> element to match or create.

forceCreation boolean

如果为 True,则只创建新元素而不检查是否已经存在。

True to create a new element without checking whether one already exists.

可选. 默认值是 `false`.
返回值

如果找到具有相同属性和值的现有元素,则找到新元素;如果找不到匹配项,则为新元素;如果未定义 tag 参数,则为 null

HTMLMetaElement | null: The existing element with the same attributes and values if found, the new element if no match is found, or null if the tag parameter is not defined.

在当前 HTML 文档中检索或创建一组 <meta>。在搜索现有标签时,Angular 会尝试在所提供的 Tag 定义中匹配 nameproperty 属性值并验证所有其他属性值是否也相等。

Retrieves or creates a set of <meta> tag elements in the current HTML document. In searching for an existing tag, Angular attempts to match the name or property attribute values in the provided tag definition, and verifies that all other attribute values are equal.

      
      addTags(tags: MetaDefinition[], forceCreation: boolean = false): HTMLMetaElement[]
    
参数
tags MetaDefinition[]

要匹配或创建的标签定义的数组。

An array of tag definitions to match or create.

forceCreation boolean

如果为 True,则创建新元素而不检查其是否已存在。

True to create new elements without checking whether they already exist.

可选. 默认值是 `false`.
返回值

匹配的元素(如果找到)或新元素。

HTMLMetaElement[]: The matching elements if found, or the new elements.

检索当前 HTML 文档中的 <meta>

Retrieves a <meta> tag element in the current HTML document.

      
      getTag(attrSelector: string): HTMLMetaElement | null
    
参数
attrSelector string

要匹配的标签属性和值,格式为 "tag_attribute='value string'"

The tag attribute and value to match against, in the format "tag_attribute='value string'".

返回值

要匹配的元素(如果有)。

HTMLMetaElement | null: The matching element, if any.

在当前 HTML 文档中检索一组 <meta> 标签。

Retrieves a set of <meta> tag elements in the current HTML document.

      
      getTags(attrSelector: string): HTMLMetaElement[]
    
参数
attrSelector string

要匹配的标签属性和值,格式为 "tag_attribute='value string'"

The tag attribute and value to match against, in the format "tag_attribute='value string'".

返回值

匹配到的元素(如果有)。

HTMLMetaElement[]: The matching elements, if any.

修改当前 HTML 文档中现有的 <meta> 标签元素。

Modifies an existing <meta> tag element in the current HTML document.

      
      updateTag(tag: MetaDefinition, selector?: string): HTMLMetaElement | null
    
参数
tag MetaDefinition

用于替换现有标签内容的标签说明。

The tag description with which to replace the existing tag content.

selector string

要匹配的标签属性和值,以标识现有标签。格式为 "tag_attribute='value string'" 字符串。如果没有提供,则改为匹配具有相同 nameproperty 属性值的标签。

A tag attribute and value to match against, to identify an existing tag. A string in the format "tag_attribute=value string". If not supplied, matches a tag with the same name or property attribute value as the replacement tag.

可选. 默认值是 `undefined`.
返回值

修改后的元素。

HTMLMetaElement | null: The modified element.

从当前 HTML 文档中删除现有的 <meta> 标签元素。

Removes an existing <meta> tag element from the current HTML document.

      
      removeTag(attrSelector: string): void
    
参数
attrSelector string

要匹配的标签属性和值,以标识现有标签。格式为 "tag_attribute='value string'" 字符串。

A tag attribute and value to match against, to identify an existing tag. A string in the format "tag_attribute=value string".

返回值

void

从当前 HTML 文档中删除现有的 <meta>

Removes an existing <meta> tag element from the current HTML document.

      
      removeTagElement(meta: HTMLMetaElement): void
    
参数
meta HTMLMetaElement

需要匹配以标识出现有标签的标签定义。

The tag definition to match against to identify an existing tag.

返回值

void