MCPcopy Create free account
hub / github.com/angular/angular / Meta

Class Meta

packages/platform-browser/src/browser/meta.ts:62–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60 */
61@Service()
62export class Meta {
63 private readonly _doc = inject(DOCUMENT);
64 private readonly _dom = getDOM();
65
66 /**
67 * Retrieves or creates a specific `<meta>` tag element in the current HTML document.
68 * In searching for an existing tag, Angular attempts to match the `name` or `property` attribute
69 * values in the provided tag definition, and verifies that all other attribute values are equal.
70 * If an existing element is found, it is returned and is not modified in any way.
71 * @param tag The definition of a `<meta>` element to match or create.
72 * @param forceCreation True to create a new element without checking whether one already exists.
73 * @returns The existing element with the same attributes and values if found,
74 * the new element if no match is found, or `null` if the tag parameter is not defined.
75 */
76 addTag(tag: MetaDefinition, forceCreation: boolean = false): HTMLMetaElement | null {
77 if (!tag) return null;
78 return this._getOrCreateElement(tag, forceCreation);
79 }
80
81 /**
82 * Retrieves or creates a set of `<meta>` tag elements in the current HTML document.
83 * In searching for an existing tag, Angular attempts to match the `name` or `property` attribute
84 * values in the provided tag definition, and verifies that all other attribute values are equal.
85 * @param tags An array of tag definitions to match or create.
86 * @param forceCreation True to create new elements without checking whether they already exist.
87 * @returns The matching elements if found, or the new elements.
88 */
89 addTags(tags: MetaDefinition[], forceCreation: boolean = false): HTMLMetaElement[] {
90 return tags
91 .filter((tag): tag is MetaDefinition => !!tag)
92 .map((tag) => this._getOrCreateElement(tag, forceCreation));
93 }
94
95 /**
96 * Retrieves a `<meta>` tag element in the current HTML document.
97 * @param attrSelector The tag attribute and value to match against, in the format
98 * `"tag_attribute='value string'"`.
99 * @returns The matching element, if any.
100 */
101 getTag(attrSelector: string): HTMLMetaElement | null {
102 if (!attrSelector) return null;
103 const meta = this._doc.querySelector<HTMLMetaElement>(buildMetaSelector(attrSelector));
104 return isMetaTag(meta) ? meta : null;
105 }
106
107 /**
108 * Retrieves a set of `<meta>` tag elements in the current HTML document.
109 * @param attrSelector The tag attribute and value to match against, in the format
110 * `"tag_attribute='value string'"`.
111 * @returns The matching elements, if any.
112 */
113 getTags(attrSelector: string): HTMLMetaElement[] {
114 if (!attrSelector) return [];
115 const list = this._doc.querySelectorAll<HTMLMetaElement>(buildMetaSelector(attrSelector));
116 return list ? Array.from(list).filter((elem) => isMetaTag(elem)) : [];
117 }
118
119 /**

Callers

nothing calls this directly

Calls 2

injectFunction · 0.90
getDOMFunction · 0.85

Tested by

no test coverage detected