projects/ngx-face-api-js/src/lib/directives/abbstract-detect.directive.ts
Properties |
Methods |
|
Accessors |
constructor(el: ElementRef
|
||||||||||||
Parameters :
|
Protected Abstract stream |
Type : boolean
|
Public task |
Type : DetectTask
|
Protected Abstract type |
Type : TaskTypeToken
|
Protected Abstract with |
Type : FeatureToken[]
|
Default value : []
|
Private createInjector |
createInjector()
|
Returns :
Injector
|
Private createOverlay |
createOverlay()
|
Returns :
any
|
ngAfterViewInit |
ngAfterViewInit()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
orverlayPositionStrategy |
getorverlayPositionStrategy()
|
import { ElementRef, Injector, OnInit, AfterViewInit } from '@angular/core';
import { Overlay, OverlayConfig } from '@angular/cdk/overlay';
import { ComponentPortal } from '@angular/cdk/portal';
import { FeatureToken, TaskTypeToken } from '../tokens';
import { DetectTask } from '../classes';
import { DetectionResultComponent } from '../components/detection-result/detection-result.component';
export abstract class AbstractDetectDirective implements OnInit, AfterViewInit {
protected abstract with: FeatureToken[] = [];
protected abstract type: TaskTypeToken;
protected abstract stream: boolean;
constructor(
protected el: ElementRef<HTMLImageElement>,
protected overlay: Overlay,
protected injector: Injector,
) {}
public task: DetectTask;
ngOnInit() {
this.task = new DetectTask({
type: this.type,
tokens: this.with,
realtime: this.stream,
});
}
private get orverlayPositionStrategy() {
return this.overlay
.position()
.flexibleConnectedTo(this.el)
.withPositions([
{
overlayX: 'start',
overlayY: 'top',
originX: 'start',
originY: 'top',
},
])
.withFlexibleDimensions(false)
.withLockedPosition(true);
}
private createOverlay() {
const scrollStrategy = this.overlay.scrollStrategies.reposition();
const config = new OverlayConfig({
positionStrategy: this.orverlayPositionStrategy,
scrollStrategy,
hasBackdrop: false,
});
return this.overlay.create(config);
}
private createInjector(): Injector {
return Injector.create({
parent: this.injector,
providers: [
{
provide: DetectTask,
useValue: this.task,
},
],
});
}
ngAfterViewInit() {
this.task.resolveTarget(this.el.nativeElement);
const overlayRef = this.createOverlay();
const injector = this.createInjector();
const portal = new ComponentPortal(
DetectionResultComponent,
undefined,
injector,
);
overlayRef.attach(portal);
}
}