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

Method _getOrCreateElement

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

Source from the content-addressed store, hash-verified

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