-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathresize.directive.ts
53 lines (46 loc) · 1.21 KB
/
resize.directive.ts
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
53
import { Directive, ElementRef, Inject, Input, OnDestroy } from '@angular/core';
import { Observable, SubscriptionLike, isObservable } from 'rxjs';
@Directive({
selector: '[auxResize]'
})
export class AuxResizeDirective extends OnDestroy
{
private subscription: SubscriptionLike = null;
constructor(@Inject(ElementRef) private el: ElementRef) { }
@Input('auxResize')
set auxResize(event: any)
{
if (this.subscription)
{
this.subscription.unsubscribe();
this.subscription = null;
}
if (!event) return;
if (isObservable(event))
{
const o = b as Observable<any>;
const element = this.el.nativeElement;
const widget = element.auxWidget;
if (!widget)
{
if (element.tagName.startsWith('AUX-'))
{
throw new Error("The AUX WebComponent has not been upgraded, yet. "+
"Are you missing and import?");
}
throw new Error("The element is not an AUX WebComponent.");
}
o.subscribe(() => {
widget.trigger_resize();
});
}
}
public ngOnDestroy()
{
if (this.subscription)
{
this.subscription.unsubscribe();
this.subscription = null;
}
}
}