import { Component, EventEmitter, Input, Output, Inject } from "@angular/core"; import { ComponentService } from "./Component.service"; import { MaterialType } from "./MaterialType"; @Component({ selector: "SelectMaterialType", providers: [ComponentService], template: `` }) export class SelectMaterialType { @Input() unitId: number; @Input() exclude: MaterialType[] = []; @Input() placeholder: string = ""; @Output() materialTypeSelect = new EventEmitter(); materialTypes: MaterialType[] = []; selectedMaterialType: MaterialType; constructor(@Inject(ComponentService) private componentService: ComponentService) {} ngOnInit() { this.componentService.getMaterialTypes(this.unitId) .subscribe(materialTypes => this.materialTypes = materialTypes); } onSelect(materialTypeItem: any) { if (materialTypeItem.item) { this.materialTypeSelect.emit(materialTypeItem.item); this.selectedMaterialType = null; } } displayedMaterialTypes(): MaterialType[] { return this.materialTypes.filter(x => !this.exclude.find(y => y.Id === x.Id)); } }