0.0.2 • Published 4 years ago

agr-dropdown v0.0.2

Weekly downloads
6
License
-
Repository
-
Last release
4 years ago

AgrDropdown

Component to show options to choose, we can filter options.

Installation

Using npm:

npm install agr-dropdown

Usage

In app.module:

// Angular
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

// Modulos
import { AppRoutingModule } from './app-routing.module';
import { AgrDropdownModule } from 'agr-dropdown';

// Componentes
import { AppComponent } from './app.component';
import { ShowcaseAgrDropdownComponent } from './example/example-agr-dropdown/example-agr-dropdown.component';

@NgModule({
  declarations: [
    AppComponent,
    ExampleAgrDropdownComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    AgrDropdownModule
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

In your ts:

import { AgrSelectItem } from 'agr-dropdown';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-example-agr-dropdown',
  templateUrl: './example-agr-dropdown.component.html',
  styleUrls: ['./example-agr-dropdown.component.css']
})
export class ExampleAgrDropdownComponent implements OnInit {

  options: AgrSelectItem[];
  valueSelect: string;

  constructor() { }

  ngOnInit() {
    this.options = [
      new AgrSelectItem('Label1', 'Value1'),
      new AgrSelectItem('Label2', 'Value2'),
      new AgrSelectItem('Label3', 'Value3'),
      new AgrSelectItem('Label4', 'Value4')
    ]
    this.valueSelect = 'Value3';
  }

  selectItem($event){
    console.log($event);
  }

}

In your html:

<div class="row">
    <div class="col-4 mt-4">
        <agr-dropdown 
            [valueSelect]="valueSelect" 
            [options]="options"
            labelNoResults="No results to show"
            (select)="selectItem($event)">

            <ng-template itemTemplate let-item="item">
                {{item.label + " - " + item.value}}
            </ng-template>

        </agr-dropdown>

        <p>This text you cant see if open dropdown</p>

    </div>
</div>

Inputs

InputDescription
optionsOptions to show
valueSelectValue of item to preload
labelNoResultsLabel to show when filter items and not found

Outputs

OutputDescription
selectEvent when select item