ng2-select icon indicating copy to clipboard operation
ng2-select copied to clipboard

How do I get started with the multi select for an angular cli project ?

Open bimalpaul opened this issue 9 years ago • 3 comments

These are the steps I followed

  1. npm i ng2-select
  2. in app.module.ts, I imported SelectModule
  3. in my component controller, added the code import { Component } from '@angular/core';
@Component({
  selector: 'multiple-demo',
  templateUrl: './multiple-demo.html'
})
export class MultipleDemoComponent {
  public items:Array<string> = ['Amsterdam', 'Antwerp', 'Athens', 'Barcelona',
    'Berlin', 'Birmingham', 'Bradford', 'Bremen', 'Brussels', 'Bucharest',
    'Budapest', 'Cologne', 'Copenhagen', 'Dortmund', 'Dresden', 'Dublin', 'Düsseldorf',
    'Essen', 'Frankfurt', 'Genoa', 'Glasgow', 'Gothenburg', 'Hamburg', 'Hannover',
    'Helsinki', 'Leeds', 'Leipzig', 'Lisbon', 'Łódź', 'London', 'Kraków', 'Madrid',
    'Málaga', 'Manchester', 'Marseille', 'Milan', 'Munich', 'Naples', 'Palermo',
    'Paris', 'Poznań', 'Prague', 'Riga', 'Rome', 'Rotterdam', 'Seville', 'Sheffield',
    'Sofia', 'Stockholm', 'Stuttgart', 'The Hague', 'Turin', 'Valencia', 'Vienna',
    'Vilnius', 'Warsaw', 'Wrocław', 'Zagreb', 'Zaragoza'];
 
  private value:any = ['Athens'];
  private _disabledV:string = '0';
  private disabled:boolean = false;
 
  private get disabledV():string {
    return this._disabledV;
  }
 
  private set disabledV(value:string) {
    this._disabledV = value;
    this.disabled = this._disabledV === '1';
  }
 
  public selected(value:any):void {
    console.log('Selected value is: ', value);
  }
 
  public removed(value:any):void {
    console.log('Removed value is: ', value);
  }
 
  public refreshValue(value:any):void {
    this.value = value;
  }
 
  public itemsToString(value:Array<any> = []):string {
    return value
      .map((item:any) => {
        return item.text;
      }).join(',');
  }
}
  1. In my component added
<div style="width: 300px; margin-bottom: 20px;">
  <h3>Select multiple cities</h3>
  <ng-select  [multiple]="true"
              [items]="items"
              [disabled]="disabled"
              (data)="refreshValue($event)"
              (selected)="selected($event)"
              (removed)="removed($event)"
              placeholder="No city selected"></ng-select>
  <pre>{{itemsToString(value)}}</pre>
  <div>
    <button type="button" class="btn btn-primary"
            [(ngModel)]="disabledV" btnCheckbox
            btnCheckboxTrue="1" btnCheckboxFalse="0">
      {{disabled === '1' ? 'Enable' : 'Disable'}}
    </button>
  </div>
</div>
  1. When I run the app, I get this error
EXCEPTION: Uncaught (in promise): Error: Error in ./SearchComponent class SearchComponent - inline template:12:12 caused by: No value accessor for form control with unspecified name attribute
Error: Error in ./SearchComponent class SearchComponent - inline template:12:12 caused by: No value accessor for form control with unspecified name attribute
    at ViewWrappedError.ZoneAwareError (http://localhost:4200/vendor.bundle.js:140040:33)

bimalpaul avatar Feb 13 '17 14:02 bimalpaul

How you fix this?

martinop avatar Feb 17 '17 16:02 martinop

I have the same issue

vicabelotelova avatar Nov 10 '17 06:11 vicabelotelova

Same issue here....

AldeRoberge avatar Mar 24 '18 17:03 AldeRoberge