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

Method _getOrCreateElement

packages/platform-browser/src/browser/meta.ts:158–176  ·  view source on GitHub ↗
(
    meta: MetaDefinition,
    forceCreation: boolean = false,
  )

Source from the content-addressed store, hash-verified

156 }
157
158 private _getOrCreateElement(
159 meta: MetaDefinition,
160 forceCreation: boolean = false,
161 ): HTMLMetaElement {
162 validateMetaDefinition(meta);
163 if (!forceCreation) {
164 const selector: string = parseSelector(meta);
165 // It's allowed to have multiple elements with the same name so it's not enough to
166 // just check that element with the same name already present on the page. We also need to
167 // check if element has tag attributes
168 const elem = this.getTags(selector).filter((elem) => containsAttributes(meta, elem))[0];
169 if (elem !== undefined) return elem;
170 }
171 const element: HTMLMetaElement = this._dom.createElement('meta') as HTMLMetaElement;
172 setMetaElementAttributes(meta, element);
173 const head = this._doc.getElementsByTagName('head')[0];
174 head.appendChild(element);
175 return element;
176 }
177}
178
179function buildMetaSelector(attrSelector: string): string {

Callers 3

addTagMethod · 0.95
addTagsMethod · 0.95
updateTagMethod · 0.95

Calls 8

getTagsMethod · 0.95
validateMetaDefinitionFunction · 0.85
parseSelectorFunction · 0.85
containsAttributesFunction · 0.85
setMetaElementAttributesFunction · 0.85
createElementMethod · 0.65
appendChildMethod · 0.65
filterMethod · 0.45

Tested by

no test coverage detected