W3cubDocs

/Angular 10

Meta

class

A service for managing HTML <meta> tags.

See more...

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
}

See also

Description

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).

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}].

Methods

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

Parameters
tag MetaDefinition

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

forceCreation boolean

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

Optional. Default is false.

Returns

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.

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[]

Parameters
tags MetaDefinition[]

An array of tag definitions to match or create.

forceCreation boolean

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

Optional. Default is false.

Returns

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

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

getTag(attrSelector: string): HTMLMetaElement | null

Parameters
attrSelector string

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

Returns

HTMLMetaElement | null: The matching element, if any.

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

getTags(attrSelector: string): HTMLMetaElement[]

Parameters
attrSelector string

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

Returns

HTMLMetaElement[]: The matching elements, if any.

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

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

Parameters
tag MetaDefinition

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

selector string

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.

Optional. Default is undefined.

Returns

HTMLMetaElement | null: The modified element.

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

removeTag(attrSelector: string): void

Parameters
attrSelector string

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

Returns

void

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

removeTagElement(meta: HTMLMetaElement): void

Parameters
meta HTMLMetaElement

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

Returns

void

© 2010–2020 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v10.angular.io/api/platform-browser/Meta