File

src/app/lib/dropdown-input/item-list/dropdown-input-item-list.component.ts

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector ul[uat-dropdown-input-items-list]
styleUrls dropdown-input-item-list.component.css
templateUrl ./dropdown-input-item-list.component.html

Index

Properties
Methods
Inputs
Outputs
HostBindings
Accessors

Constructor

constructor(chDetRef: ChangeDetectorRef)
Parameters :
Name Type Optional Description
chDetRef ChangeDetectorRef

Inputs

dynamicComponentsData

Type: DropdownItemComponentData[]

Outputs

listItemClick $event type: EventEmitter
listItemMouseOver $event type: EventEmitter
newContainers $event type: EventEmitter

HostBindings

class.uat-dropdown-input-items-list
class.uat-dropdown-input-items-list:
Default value : true

Methods

Public changeAutoSelection
changeAutoSelection(index: number, selected: boolean)
Parameters :
Name Type Optional Description
index number
selected boolean
Returns : void
Public changeSelection
changeSelection(index: number, selected: boolean)
Parameters :
Name Type Optional Description
index number
selected boolean
Returns : void
ngAfterViewInit
ngAfterViewInit()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
onListItemClick
onListItemClick(e: MouseEvent, index: number)
Parameters :
Name Type Optional Description
e MouseEvent
index number
Returns : void
onListItemMouseOver
onListItemMouseOver(e: MouseEvent, index: number)
Parameters :
Name Type Optional Description
e MouseEvent
index number
Returns : void

Properties

Public dynamicComponentClasses
dynamicComponentClasses: any[]
Type : any[]
Public dynamicComponentContainers
dynamicComponentContainers: QueryList<UATDynamicComponentDirective>
Type : QueryList<UATDynamicComponentDirective>
Decorators : ViewChildren
Private itemAutoSelected
itemAutoSelected: boolean[]
Type : boolean[]
Private itemSelected
itemSelected: boolean[]
Type : boolean[]
Public listItems
listItems: QueryList<ViewContainerRef>
Type : QueryList<ViewContainerRef>
Decorators : ViewChildren
Private newContainersSub
newContainersSub: Subscription
Type : Subscription

Accessors

listElements
getlistElements()
import {
    Component,
    ComponentRef,
    Input,
    Output,
    EventEmitter,
    ComponentFactoryResolver,
    ReflectiveInjector,
    ViewContainerRef,
    ViewChildren,
    QueryList,
    ChangeDetectionStrategy,
    ChangeDetectorRef,
    HostBinding,
} from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
import { DropdownItemComponentData } from '../service/dropdown-input-service.interface';
import { UATDynamicComponentDirective } from '../../dynamic-component/dynamic-component.directive';
import { DropdownInputItemsMouseEvent } from '../events/dropdown-input-item-events.interface';

@Component({
    selector:'ul[uat-dropdown-input-items-list]',
    templateUrl: './dropdown-input-item-list.component.html',
    styleUrls: ['./dropdown-input-item-list.component.css'],
    changeDetection: ChangeDetectionStrategy.OnPush
})
export class UATDropdownInputItemsList {
    @HostBinding('class.uat-dropdown-input-items-list') applyHostClass = true;

    @Input() public dynamicComponentsData: DropdownItemComponentData[] = [];

    public dynamicComponentClasses: any[];

    @ViewChildren('container') 
        public dynamicComponentContainers: QueryList<UATDynamicComponentDirective>;

    @ViewChildren('listItem',{read:ViewContainerRef})
        public listItems: QueryList<ViewContainerRef>;

    public get listElements() {
        return this.listItems.toArray().map(li=>{
            return (li.element.nativeElement as HTMLLIElement);
        });
    }

    @Output() public newContainers = new EventEmitter<UATDynamicComponentDirective[]>();

    @Output() public listItemMouseOver = new EventEmitter<DropdownInputItemsMouseEvent>();

    @Output() public listItemClick = new EventEmitter<DropdownInputItemsMouseEvent>();

    private newContainersSub: Subscription;

    private itemAutoSelected: boolean[] = [];
    private itemSelected: boolean[] = [];

    constructor(private chDetRef: ChangeDetectorRef) {
    }

    public changeSelection(index:number, selected: boolean) {
        this.itemSelected[index]=selected;
        this.chDetRef.markForCheck();
        this.chDetRef.detectChanges();
    }

    public changeAutoSelection(index: number, selected: boolean) {
        this.itemAutoSelected[index]=selected;
        this.chDetRef.markForCheck();
        this.chDetRef.detectChanges();
    }

    ngAfterViewInit() {
        // emit the original list
        this.newContainers.emit(this.dynamicComponentContainers.toArray());
        
        if (this.newContainersSub) {
            this.newContainersSub.unsubscribe();
        }

        this.newContainersSub =
            this.dynamicComponentContainers
                .changes
                .subscribe(
                    newList => {
                        this.itemAutoSelected = [];
                        this.itemSelected = [];
                        this.newContainers.emit(newList.toArray());
                    },
                    (error: string) => console.log(error),
                    () => {
                        this.newContainersSub.unsubscribe()
                    });
    }

    ngOnDestroy() {
        if (this.newContainersSub) {
            this.newContainersSub.unsubscribe();
        }
    }

    onListItemClick(
        e: MouseEvent, 
        index: number){
        this.listItemClick.emit({
            event: e,
            index: index
        });
    }

    onListItemMouseOver(
        e: MouseEvent, 
        index: number) {
        this.listItemMouseOver.emit({
            event: e,
            index: index
        });
    }
}

<li *ngFor="let compData of dynamicComponentsData; let i = index;"
    #listItem
    class="item"
    [class.auto-selected]="itemAutoSelected[i]"
    [class.selected]="itemSelected[i]"
    (click)="onListItemClick($event, i)"
    (mouseover)="onListItemMouseOver($event, i)">
    <ng-template #container="dynamicComp" [uat-dynamic-component]="compData"></ng-template>
</li>


Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""