npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng2-iq-select2

v9.0.2

Published

[![InnQUbe](http://www.innqube.com/assets/images/badge.svg)](http://www.innqube.com/) [![Build Status](https://travis-ci.org/Innqube/ng2-iq-select2.svg?branch=master)](https://travis-ci.org/Innqube/ng2-iq-select2) [![codecov](https://codecov.io/gh/Innqube

Downloads

542

Readme

ng2-iq-select2

InnQUbe Build Status codecov Code Climate

Angular 2 native select 2 implementation based on bootstrap 4

  • Easily filter on a remote webservice (can be used with a local list too)
  • Works with ids or complete entities
  • Single or multiple modes
  • Forms integration
  • MIT License
  • Last bootstrap 3 compatible version is 7.0.0

Take a look at the demo page


Usage example:

app.module.ts


import { IqSelect2Module } from 'ng2-iq-select2';

@NgModule({
    declarations: [..],
    imports: [.., IqSelect2Module, ...],
    providers: [..]

html file

<form [formGroup]="form">
    <iq-select2 css="form-control input-sm" 
                formControlName="country" 
                [dataSourceProvider]="listCountries"
                [selectedProvider]="loadFromIds"
                [iqSelect2ItemAdapter]="adapter"></iq-select2>
</form>

html file (custom template)

<form [formGroup]="form">
  <iq-select2 css="form-control input-sm" 
                formControlName="country" 
                [dataSourceProvider]="listCountries"
                [selectedProvider]="loadFromIds"
                [iqSelect2ItemAdapter]="adapter">
    <div *iq-select2-template="let item = $entity; let i = $index">
      <span [style.color]="item.color">[{{item.code}}]</span> {{item.name}}
    </div>
  </iq-select2>
</form>

Exposed internal variable to bind $item, $entity, $id, $index

example typescript file

export class Example {
    form: FormGroup;
    listCountries: (term: string) => Observable<Country[]>;
    loadFromIds: (ids: string[]) => Observable<Country[]>;
    adapter: (entity: Country) => IqSelect2Item;
//
    constructor(private countriesService: CountryService,
                private formBuilder: FormBuilder){
    
    }
//
    ngOnInit() {
        this.listCountries = (term: string) => this.countriesService.listCountries(term);
        this.loadFromIds = (ids: string[]) => this.countriesService.loadCountriesFromIds(ids);
        this.adapter = (country: Country) => {
            return {
                id: country.id,
                text: country.name,
                entity: country
            };
        }
        this.form = this.formBuilder.group({
            country: null
        });
    }
};

IqSelect2Item

interface IqSelect2Item {
    id: string;
    text: string;
    entity?: any; // only needed when referenceMode === 'entity'
}

Messages

export class Messages {
    
     static readonly PARTIAL_COUNT_VAR; // Variable to be replaced by the amount of results being shown
     static readonly TOTAL_COUNT_VAR; // Variable to be replaced by the total count of results
    
    moreResultsAvailableMsg?: string;
    noResultsAvailableMsg?: string;
}

Configuration options (Inputs and Outputs)

@Input() dataSourceProvider: (term: string, selected?: any[]) => Observable<IqSelect2Item[]>: the function to get the data based on user input. Selected ids or entities are provided in case you want to avoid getting those results again (this could be useful when setting the "resultsCount" property).

@Input() selectedProvider: (ids: string[]) => Observable<IqSelect2Item[]>: the function to get previously selected data when referenceMode === 'id'

@Input() iqSelect2ItemAdapter: (entity: T) => IqSelect2Item: the function to adapt any entity to a IqSelect2Item

@Input() referenceMode: 'id' | 'entity'. Allows to specify if you need the whole entity or just the id.

@Input() multiple: 'true' | 'false'. Allows to select multiple options from the list. The form value is returned as an array.

@Input() clientMode: 'true' | 'false'. If set to true only one request will be sent to the data provider and subsequent searching will happen on the client.

@Input() searchDelay: ms until request is effectively triggered

@Input() placeholder: text to show until a search is performed

@Input() disabled: boolean to control the disabled state of the component

@Input() minimumInputLength: the minimum input length at which the component will request data to the provider

@Input() resultsCount: total count of results produced after entering the search term. A message suggesting further filtering will appear if the results count is greather than the result list shown

@Input() messages: Messages: class to provide custom messages to the component

@Input() css: css classes to be applied

@Input() searchIcon: css icon on the right of the input

@Input() deleteIcon: css icon to be used to remove selected option (In single mode)

@Input() badgeColor: badge bootstrap color: 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'light' | 'dark'

@Output() onSelect(item: IqSelect2Item): event triggered when an item is selected

@Output() onRemove(item: IqSelect2Item): event triggered when an item is removed


Reference mode examples

// form.value example with referenceMode === 'id':
{
    'item': 1
}

// form.value example with referenceMode === 'entity':
{
    'item':  {
        'id': 1,
        'property1': 'value',
        ...
    }
}

// form.value example with referenceMode === 'id' and multiple === 'true':
{
    'item': [1,2,3]
}

// form.value example with referenceMode === 'entity' and multiple === 'true':
{
    'item': [{
        'id': 1,
        'property1': 'value',
        ...
    },{
        'id': 2,
        'property1': 'value2',
        ...
    },{
        'id': 3,
        'property1': 'value3',
        ...
    }]
}