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

Method _getOrCreateElement

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

Source from the content-addressed store, hash-verified

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

Callers 3

addTagMethod · 0.95
addTagsMethod · 0.95
updateTagMethod · 0.95

Calls 7

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

Tested by

no test coverage detected