Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | 1x 166x 166x 1x 251x 251x 1x 417x 417x 417x 75x 75x 75x 155x 342x 1x 16x 16x 16x | import { ElementRef } from '@angular/core';
const projectContent = (elementRef: ElementRef, templateSelector: string, targetSelector: string): void => {
const element: Element = elementRef.nativeElement.querySelector(targetSelector);
project(element, elementRef, templateSelector);
};
const projectSourceContent = (elementRef: ElementRef, sourceElementRef: ElementRef, templateSelector: string): void => {
const element: Element = elementRef.nativeElement;
project(element, sourceElementRef, templateSelector);
};
const project = (element: Element, sourceElementRef: ElementRef, templateSelector: string): void => {
const templates: Array<HTMLTemplateElement> = Array.from(sourceElementRef.nativeElement.querySelectorAll(templateSelector));
Eif (!!element) {
if (templates.length) {
templates.forEach((template: HTMLTemplateElement) => {
const clone: Node = template.children.length === 0 && template.content.children.length > 0
? template.content.cloneNode(true)
: template;
Array.from((clone as Node).childNodes)
.forEach((child: Node) => {
element.appendChild(child);
});
});
}
else {
// hide target element if nothing to project
(element as HTMLElement).hidden = true;
}
}
};
const preserveContent = (elementRef: ElementRef, templateSelector: string, targetSelector: string): void => {
const element: Element = elementRef.nativeElement.querySelector(targetSelector);
const template: HTMLTemplateElement = elementRef.nativeElement.querySelector(templateSelector);
Iif (!!element && !!template) {
Array.from(element.children)
.filter((elem: Element) => elem.nodeName !== 'TEMPLATE')
.forEach((elem: Element) => {
template.appendChild(elem);
});
}
};
export {
projectContent,
projectSourceContent,
preserveContent
};
|