src/comps/sliderpanel/Slideritem.ts
Compbaser
selector | Slideritem |
template |
|
from
|
Type: |
Defined in src/comps/sliderpanel/Slideritem.ts:69
|
fromDirection
|
Type: |
Defined in src/comps/sliderpanel/Slideritem.ts:67
|
showFromButton
|
Type:
Default value: |
Defined in src/comps/sliderpanel/Slideritem.ts:71
|
showToButton
|
Type:
Default value: |
Defined in src/comps/sliderpanel/Slideritem.ts:70
|
templateRef
|
Type: |
Defined in src/comps/sliderpanel/Slideritem.ts:65
|
to
|
Type: |
Defined in src/comps/sliderpanel/Slideritem.ts:68
|
toDirection
|
Type: |
Defined in src/comps/sliderpanel/Slideritem.ts:66
|
onChange
|
$event type: Observable<ISliderItemData>
|
Defined in src/comps/sliderpanel/Slideritem.ts:72
|
constructor(viewContainer: ViewContainerRef, sliderPanel: Sliderpanel, cd: ChangeDetectorRef, ap: ApplicationRef)
|
Defined in src/comps/sliderpanel/Slideritem.ts:31
|
ngDoCheck |
ngDoCheck()
|
Defined in src/comps/sliderpanel/Slideritem.ts:47
|
Returns :
void
|
Static addClass |
addClass(i_className: any)
|
Defined in src/comps/sliderpanel/Slideritem.ts:74
|
Returns :
void
|
Static hasClass |
hasClass(i_className: any)
|
Defined in src/comps/sliderpanel/Slideritem.ts:78
|
Returns :
void
|
Static getNative |
getNative()
|
Defined in src/comps/sliderpanel/Slideritem.ts:82
|
Returns :
void
|
Static removeClass |
removeClass(i_className: any)
|
Defined in src/comps/sliderpanel/Slideritem.ts:86
|
Returns :
void
|
Static slideTo |
slideTo(to: string, direction: string)
|
Defined in src/comps/sliderpanel/Slideritem.ts:90
|
Returns :
void
|
Static onNext |
onNext()
|
Defined in src/comps/sliderpanel/Slideritem.ts:99
|
Returns :
void
|
Static onPrev |
onPrev()
|
Defined in src/comps/sliderpanel/Slideritem.ts:103
|
Returns :
void
|
destroy |
destroy()
|
Defined in src/comps/sliderpanel/Slideritem.ts:107
|
Returns :
void
|
m_onChanges$ |
m_onChanges$: |
Defined in src/comps/sliderpanel/Slideritem.ts:31
|
m_render |
m_render: |
Default value : false
|
Defined in src/comps/sliderpanel/Slideritem.ts:30
|
import {ApplicationRef, ChangeDetectorRef, Component, DoCheck, Input, Output, TemplateRef, ViewContainerRef} from "@angular/core";
import {Sliderpanel} from "./Sliderpanel";
import {Observable, Subject} from "rxjs";
import {Compbaser} from "ng-mslib";
export interface ISliderItemData {
to: string;
direction: string;
}
@Component({
selector: 'Slideritem',
// changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<button *ngIf="fromDirection && showFromButton" type="button" (click)="onPrev()" class="btn btn-default btn-sm">
<span class="fa fa-arrow-left "></span>
</button>
<button *ngIf="toDirection && showToButton" type="button" (click)="onNext()" class="btn btn-default btn-sm">
<span class="fa fa-arrow-right"></span>
</button>
<!--<ng-content *ngIf="m_render"></ng-content>-->
<ng-template *ngIf="m_render" [ngTemplateOutlet]="templateRef"></ng-template>
`,
})
export class Slideritem extends Compbaser implements DoCheck {
m_render: boolean = false;
m_onChanges$ = new Subject()
constructor(private viewContainer: ViewContainerRef, protected sliderPanel: Sliderpanel, private cd: ChangeDetectorRef, ap: ApplicationRef) {
super();
this.viewContainer.element.nativeElement.classList.add('page');
this.sliderPanel.addSlider(this);
this.cancelOnDestroy(
this.m_onChanges$.debounceTime(300)
.subscribe((data: any) => {
this.sliderPanel.slideToPage(data.to, data.direction)
this.cd.markForCheck();
})
)
}
ngDoCheck() {
if (this.viewContainer.element.nativeElement.classList.contains('selected')) {
if (this.m_render == true)
return;
this.m_render = true;
// console.log('added');
this.cd.detectChanges();
} else {
if (this.m_render == false)
return;
setTimeout(() => {
this.m_render = false;
// console.log('removed');
this.cd.detectChanges();
}, 500)
}
}
@Input() templateRef: TemplateRef<any>;
@Input() toDirection: 'left' | 'right';
@Input() fromDirection: 'left' | 'right';
@Input() to: string;
@Input() from: string;
@Input() showToButton: boolean = true;
@Input() showFromButton: boolean = true;
@Output() onChange: Observable<ISliderItemData> = new Subject().delay(300).debounceTime(1000);
public addClass(i_className) {
this.viewContainer.element.nativeElement.classList.add(i_className);
}
public hasClass(i_className) {
this.viewContainer.element.nativeElement.classList.contains(i_className);
}
public getNative() {
return this.viewContainer.element.nativeElement;
}
public removeClass(i_className) {
this.viewContainer.element.nativeElement.classList.remove(i_className);
}
public slideTo(to: string, direction: string) {
(this.onChange as Subject<ISliderItemData>).next({
to: to,
direction: direction
})
this.m_onChanges$.next({to, direction})
// this.sliderPanel.slideToPage(to, direction)
}
public onNext() {
this.slideTo(this.to, this.toDirection);
}
public onPrev() {
this.slideTo(this.from, this.fromDirection);
}
destroy() {
// console.log('dest SliderItem');
}
}