All Projects → Froiden → angular2-select

Froiden / angular2-select

Licence: MIT license
No description or website provided.

Programming Languages

typescript
32286 projects
CSS
56736 projects

Projects that are alternatives of or similar to angular2-select

Angular Select2
select2 in angular(>=2.0-release).
Stars: ✭ 16 (+33.33%)
Mutual labels:  angular2, select2
Cc
一个基于angular5.0.0+ng-bootstrap1.0.0-beta.8+bootstrap4.0.0-beta.2+scss的后台管理系统界面(没基础的同学请先自学基础,谢谢!)
Stars: ✭ 416 (+3366.67%)
Mutual labels:  angular2, select2
angular2-simple-countdown
a simple countdown angular2 directive with multiple language
Stars: ✭ 26 (+116.67%)
Mutual labels:  angular2
Advanced-MultiSelect-for-Dynamics
Advanced MultiSelect for Dynamics 365 / Dynamics CRM is a multi-select / multi-checkbox control on a form. It represents a set of related data items (based on N:N relations + FetchXml) and gives a user an ability to associate/disassociate records of related entities in a quick and convenient way.
Stars: ✭ 14 (+16.67%)
Mutual labels:  multi-select
laravel5Angular4
Laravel 5.4 & Angular 4.3.4
Stars: ✭ 37 (+208.33%)
Mutual labels:  angular2
paper-dashboard-angular
Angular version of the original Paper Dashboard.
Stars: ✭ 142 (+1083.33%)
Mutual labels:  angular2
angular2-webpack-advance-starter
An advanced Angular2 Webpack Starter project with support for ngrx/store, ngrx/effects, ng2-translate, angulartics2, lodash, NativeScript (*native* mobile), Electron (Mac, Windows and Linux desktop) and more.
Stars: ✭ 49 (+308.33%)
Mutual labels:  angular2
angular-build-info
🛠 A CLI to generate an easily importable `build.ts` file containing various details about the application build
Stars: ✭ 25 (+108.33%)
Mutual labels:  angular2
capybara select2
Capybara helpers for https://select2.org select box (supports Select2 version 2/3/4)
Stars: ✭ 48 (+300%)
Mutual labels:  select2
nodeJS examples
Server, routing, db examples using NodeJS v6
Stars: ✭ 34 (+183.33%)
Mutual labels:  angular2
gupack
基于gulp的前端构建工具
Stars: ✭ 13 (+8.33%)
Mutual labels:  angular2
react-native-multi-selectbox
Platform independent (Android / iOS) Selectbox | Picker | Multi-select | Multi-picker. The idea is to bring out the common user interface & user experience on both platforms.
Stars: ✭ 169 (+1308.33%)
Mutual labels:  multi-select
ionic-video-chat-support
Ionic 3 Video and Group Text Chat
Stars: ✭ 19 (+58.33%)
Mutual labels:  angular2
ngx-json-ld
📝 A small component to easily bind JSON-LD schema to Angular templates.
Stars: ✭ 29 (+141.67%)
Mutual labels:  angular2
ng2-fontawesome
An easy-to-use directive for font awesome icons.
Stars: ✭ 20 (+66.67%)
Mutual labels:  angular2
Angular2-startbootstrap-new-age
Angular 2 version of the Start Bootstrap New Age theme
Stars: ✭ 13 (+8.33%)
Mutual labels:  angular2
ng-pdf-make
This is library creates a bridge to use pdfmake library with your angular 2 implementation.
Stars: ✭ 15 (+25%)
Mutual labels:  angular2
ng2-storage
A local and session storage wrapper for angular 2.
Stars: ✭ 14 (+16.67%)
Mutual labels:  angular2
ngx-widget-grid
Angular 2.x or in general ng-x module for dashboards
Stars: ✭ 65 (+441.67%)
Mutual labels:  angular2
Knight
The scheduler with UI base on quartz-scheduler(spring boot + angular)
Stars: ✭ 16 (+33.33%)
Mutual labels:  angular2

Angular2 Select component

froiden-angular2-select npm version npm downloads

Getting started

Install

npm install --save froiden-angular2-select

Examples

  1. Without Ajax Single Select
  2. Without Ajax Multi Select
  3. With Ajax Single Select
  4. With Ajax Multi Select
  5. Update with Ajax Multi Select

Add angular2-select.css

Include angular2-select.css in your controller. Add css in your component class

    import { Component} from "@angular/core";
    .......

    @Component({
        ....
        ....
        styleUrls : ["./angular2-select.css"]
    })

Configuration

Systemjs

In systemjs.config.js add froiden-angular2-select to map and package:

var map = {
	// others...,
	'froiden-angular2-select': 'node_modules/froiden-angular2-select'
};

var packages = {
	// others...,
	'froiden-angular2-select': {
		main: 'angular2-select.js',
		defaultExtension: 'js'
	}
};

Usage

Import the SelectModule and define it as one of the imports of your application module:

import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {FormsModule} from '@angular/forms';
import {SelectModule} from 'froiden-angular2-select/angular2-select';

import {AppComponent} from './app.component';

@NgModule({
    imports: [
        BrowserModule,
        FormsModule,
        SelectModule
    ],
    declarations: [
        AppComponent
    ],
    bootstrap: [
        AppComponent
    ]
})
export class AppModule { }

Add the following HTML to the component template in which you want to use the select component:

<ng-select name="countries" [(ngModel)]="countries"
           [settings]="selectOptions">
</ng-select>

Within the component class you have to set the countries and dataObject variable. We can set select2 data using ajax or without ajax.

Without Ajax request

    public countries : any;
    private selectOptions = {
        "idField" : "id",
        "textField" : "text",
        "multiple" : true,
        "allowClear" : true,
        "debounceTime" : 300,
        "placeholder" : "Select countries...",
        data :   [
            {
                "id" : 1,
                "text" : "India"
            },
            {
                "id" : 2,
                "text" : "Bangladesh"
            },
            .....
        ],
        processResults : (modelObject : any) => {
            let selectValues : Array<any> = [];
            modelObject.forEach((item : {id : number, text : string}) => {
                selectValues.push({
                    id : item.id,
                    text : item.text,
                });
            });
            return selectValues;
        }
    }

With Ajax request

    public countries : any;
    private selectOptions = {
        "idField" : "id",
        "textField" : "text",
        "multiple" : true,
        "allowClear" : true,
        "debounceTime" : 300,
        "placeholder" : "Select countries...",
        ajax : {
            "requestType" : "get",
            "url"      : 'http://demo.com/api/countries?fields=id|name&limit=-1&filters={"name":{"type":"search","value":"SEARCH_VALUE"}}',
            "authToken": AUTH TOKEN IF REQUIRED,
            responseData : (response : any) => {
                let currentValue = response.data;
                let value : Array<any> = [];
                currentValue.forEach((item : {id : number, name : string}) => {
                    value.push({
                        id  : item.id,
                        text: item.name
                    });
                });
                return value;
            }
        },
        processResults : (modelObject : any) => {
            let selectValues : Array<any> = [];
            modelObject.forEach((item : {id : number, text : string}) => {
                selectValues.push({
                    id : item.id,
                    text : item.text,
                });
            });
            return selectValues;
        }
    }

NOTE: Always put SEARCH_VALUE in your url. We will automatically replace SEARCH_VALUE with input entered by you.

For Update (With Ajax request)View Demo

    public countries : any = [{
       "countryCode" : '1',
       "countryName" : "India"
   }];
    private selectOptions = {
        "idField" : "countryCode",
        "textField" : "countryName",
        "multiple" : true,
        "allowClear" : true,
        "debounceTime" : 300,
        "placeholder" : "Select countries...",
        ajax : {
            "requestType" : "get",
            "url"      : 'http://demo.com/api/countries?fields=id|name&limit=-1&filters={"name":{"type":"search","value":"SEARCH_VALUE"}}',
            "authToken": AUTH TOKEN IF REQUIRED,
            responseData : (response : any) => {
                let currentValue = response.data;
                let value : Array<any> = [];
                currentValue.forEach((item : {isoCode : string, name : string}) => {
                    value.push({
                        countryCode  : item.isoCode,
                        countryName: item.name
                    });
                });
                return value;
            }
        },
        processResults : (modelObject : any) => {
            let selectValues : Array<any> = [];
            modelObject.forEach((item : {countryCode : string, countryName : string}) => {
                selectValues.push({
                    countryCode : item.countryCode,
                    countryName : item.countryName,
                });
            });
            return selectValues;
        }
    }

NOTE: Always put SEARCH_VALUE in your url. We will automatically replace SEARCH_VALUE with input entered by you.

[(ngModel)]

You need to set [(ngModel)] with your Component variable for which you want two way data binding.

Input properties (selectOptions)

idField(optional)

default - id

String value to set id field.

textField(optional)

default - text

String value to set text field.

multiple

true/false

A boolean to choose between single and multi-select.

allowClear

true/false

If set to true, a button with a cross that can be used to clear the currently selected option is shown if an option is selected.

debounceTime

Integer value

Time for which you want to wait to appear select options.

placeholder

default: ''

The placeholder value is shown if no option is selected.

processResults

Callback function to set ngModel array of object. For single select:

processResults : (modelObject : any) => {
    let selectValues : Array<any> = [];
    selectValues.push({
        id : item.id,
        textValue : item.text,
    });
    return selectValues;
}

For multiple select :

processResults : (modelObject : any) => {
    let selectValues : Array<any> = [];
    modelObject.forEach((item : {id : number, text : string}) => {
        selectValues.push({
            id : item.id,
            textValue : item.text,
        });
    });
    return selectValues;
}

Input properties (selectOptions.ajax)

If you want to use ajax request to fetch data from url and want to render this data into your select option then we will use following properties:

requestType

get/post

Request type for url address.

url

string

URL address from where you will fetch data for select options. NOTE: Always put SEARCH_VALUE in your url. We will automatically replace SEARCH_VALUE with input entered by you.

authToken (optional)

string

If your url endpoint uses auth token then assign to authToken

responseData

Callback function to set select option values:

responseData : (response : any) => {
    let currentValue = response.data;
    let value : Array<any> = [];
    currentValue.forEach((item : {id : number, name : string}) => {
        value.push({
            id  : item.id,
            text: item.name
        });
    });
    return value;
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].