1

i have installed angular2-select and have defined that in module.ts as well. But when i click on select button, there are 2 contents but the contents are not visible, can anyone help me to solve this.

HTML:

<div class="form-group">
<label >Category Type</label>
<ng-select [options]="category" [(ngModel)]="category.name" name="category" class='filterDropDown' placeholder="Category" notFoundMsg="No Category Found">
 </ng-select>
 </div>

ts: category:any = [{name:'school'},{name:'college'}];

2
  • Will you please create a plnkr for this ? Commented Nov 14, 2017 at 7:30
  • I have no idea to create plunker, can i share pics, how it is coming Commented Nov 14, 2017 at 7:43

2 Answers 2

1

According to angular-2 select, the options take in items array

Also, use ng-2 select instead of angular-2 select

import {SelectModule} from 'ng2-select'

According to its documentation here, official documentation it requires,

items - (Array<any>) - Array of items from which to select. Should be an array of objects with id and text properties. As convenience, you may also pass an array of strings, in which case the same string is used for both the ID and the text.

So, your object shoud be either,

category:any = [{ id: 'school', text:'school'},{id: 'college', text:'college'}];

<ng-select [items]="category" [(ngModel)]="category.id" name="category" class='filterDropDown' placeholder="Category" notFoundMsg="No Category Found">
 </ng-select>

or

category:any = ['school', 'college'];

<ng-select [items]="category" [(ngModel)]="category" name="category" class='filterDropDown' placeholder="Category" notFoundMsg="No Category Found">
 </ng-select>

PS: You can use angular2-select change the object to,

import {SelectModule} from 'angular2-select'

It uses, value and label and use same [options] in html

category:any = [{ label: 'school', value:'school'},{label: 'college', value:'college'}];

<ng-select [options]="category" [(ngModel)]="category.label" name="category" class='filterDropDown' placeholder="Category" notFoundMsg="No Category Found">
 </ng-select>
Sign up to request clarification or add additional context in comments.

Comments

0
<ng-select [**items**]="category" [(ngModel)]="category.name" name="category" class='filterDropDown' placeholder="Category" notFoundMsg="No Category Found">

It is items not options

1 Comment

Thanks for the response, if i use items instead of options, i get this error " Can't bind to 'items' since it isn't a known property of 'ng-select'. "

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.