{ "id": "api/platform-browser/Meta", "title": "Meta", "contents": "\n\n
\n
\n
\n \n API > @angular/platform-browser\n
\n \n
\n \n
\n

Metalink

\n \n \n \n \n \n
\n \n \n\n
\n \n
\n

A service for managing HTML <meta> tags.

\n\n

See more...

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

See alsolink

\n \n
\n\n\n \n \n
\n

Descriptionlink

\n

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

\n

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

\n\n \n
\n\n \n\n\n\n\n\n\n\n\n\n\n\n\n
\n

Methodslink

\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n

\n addTag()\n \n link

\n \n
\n
\n

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

\n\n
\n
\n \n\n addTag(tag: MetaDefinition, forceCreation: boolean = false): HTMLMetaElement | null\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n \n tag\n MetaDefinition\n

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

\n\n
\n \n forceCreation\n boolean\n

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

\n

Optional. Default is false.

\n\n
\n\n \n
Returns
\n

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

\n\n \n\n\n \n\n \n
\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n

\n addTags()\n \n link

\n \n
\n
\n

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

\n\n
\n
\n \n\n addTags(tags: MetaDefinition[], forceCreation: boolean = false): HTMLMetaElement[]\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n \n tags\n MetaDefinition[]\n

An array of tag definitions to match or create.

\n\n
\n \n forceCreation\n boolean\n

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

\n

Optional. Default is false.

\n\n
\n\n \n
Returns
\n

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

\n\n \n\n\n \n\n \n
\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n

\n getTag()\n \n link

\n \n
\n
\n

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

\n\n
\n
\n \n\n getTag(attrSelector: string): HTMLMetaElement | null\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n
\n \n attrSelector\n string\n

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

\n\n
\n\n \n
Returns
\n

HTMLMetaElement | null: The matching element, if any.

\n\n \n\n\n \n\n \n
\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n

\n getTags()\n \n link

\n \n
\n
\n

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

\n\n
\n
\n \n\n getTags(attrSelector: string): HTMLMetaElement[]\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n
\n \n attrSelector\n string\n

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

\n\n
\n\n \n
Returns
\n

HTMLMetaElement[]: The matching elements, if any.

\n\n \n\n\n \n\n \n
\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n

\n updateTag()\n \n link

\n \n
\n
\n

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

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

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

\n\n
\n \n selector\n string\n

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

\n

Optional. Default is undefined.

\n\n
\n\n \n
Returns
\n

HTMLMetaElement | null: The modified element.

\n\n \n\n\n \n\n \n
\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n

\n removeTag()\n \n link

\n \n
\n
\n

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

\n\n
\n
\n \n\n removeTag(attrSelector: string): void\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n
\n \n attrSelector\n string\n

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

\n\n
\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n

\n removeTagElement()\n \n link

\n \n
\n
\n

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

\n\n
\n
\n \n\n removeTagElement(meta: HTMLMetaElement): void\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n
\n \n meta\n HTMLMetaElement\n

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

\n\n
\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n\n \n
\n\n\n\n \n\n\n
\n
\n\n\n" }