File

src/app/shared/components/drop-down/drop-down.component.ts

Description

DropDown Component

Metadata

selector app-dropdown
templateUrl ./drop-down.component.html

Index

Methods
Inputs
Outputs

Inputs

data

array of dropdown items

field

field of item in data which should be displayed in dropdown (e.g. name or projectName)

label

dropdown label

selected

selected item

Outputs

change
Type : EventEmitter<string>

change event emitter

Methods

onChange
onChange(item: any)

On dropdown item click, emit an event to parent

Parameters :
Name Type Optional Description
item any No

: dropdown item

Returns : void
import {Component, EventEmitter, Input, Output} from '@angular/core';

/**
 * DropDown Component
 */
@Component({
  selector: 'app-dropdown',
  templateUrl: './drop-down.component.html',
  // styleUrls: ['./drop-down.component.scss']
})

export class DropDownComponent{
  /**
   * array of dropdown items
   */
  @Input() data;

  /**
   * selected item
   */
  @Input() selected;

  /**
   * dropdown label
   */
  @Input() label;

  /**
   * field of item in data which should be displayed in dropdown (e.g. name or projectName)
   */
  @Input() field;

  /**
   * change event emitter
   */
  @Output() change: EventEmitter<string> = new EventEmitter<string>();

  /**
   * On dropdown item click, emit an event to parent
   * @param item: dropdown item
   */
  onChange(item: any) {
      this.change.emit(item);
  }
}
<ng-container class="col-md-6" *ngIf="data">
  <div class="btn-group mr-3 w-100 align-items-center">
    <span class="flex-shrink-0 mr-3">{{label}}:</span>
    <div class="btn-group w-100" ngbDropdown role="group" aria-label="Button group">
      <button class="btn btn-primary" ngbDropdownToggle>{{selected}}</button>
      <div ngbDropdownMenu class="dropdown-menu w-100">
        <button ngbDropdownItem class="dropdown-item" *ngFor="let item of data" (click)="onChange(item)" >{{item[field]}}</button>
      </div>
    </div>
  </div>
</ng-container>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""