File

src/comps/sliderpanel/Slideritem.ts

Extends

Compbaser

Implements

DoCheck

Metadata

selector Slideritem
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>

Inputs

from

Type: string

fromDirection

Type: "left" | "right"

showFromButton

Type: boolean

Default value: true

showToButton

Type: boolean

Default value: true

templateRef

Type: TemplateRef<any>

to

Type: string

toDirection

Type: "left" | "right"

Outputs

onChange $event type: Observable<ISliderItemData>

Constructor

constructor(viewContainer: ViewContainerRef, sliderPanel: Sliderpanel, cd: ChangeDetectorRef, ap: ApplicationRef)

Methods

ngDoCheck
ngDoCheck()
Returns : void
Static addClass
addClass(i_className: any)
Returns : void
Static hasClass
hasClass(i_className: any)
Returns : void
Static getNative
getNative()
Returns : void
Static removeClass
removeClass(i_className: any)
Returns : void
Static slideTo
slideTo(to: string, direction: string)
Returns : void
Static onNext
onNext()
Returns : void
Static onPrev
onPrev()
Returns : void
destroy
destroy()
Returns : void

Properties

m_onChanges$
m_onChanges$: Subject<{}>
m_render
m_render: boolean
Default value : false
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');
    }
}

Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""