0

I am using angular2 and for drop downs. Whenever a do a search in the drop down and listed items matching criteria highlights the text searched for and on click of which it does not get selected item in the drop down. When you select any other text apart from searched text in the item listed, it gets selected. What causes this behaviour?

Code is as mentioned:

<ng-select [items]="tests"
           (data)="updateSelected($event')"
           [active]="selectChannel"
           id="channelList{{tabId}}"
           style="float: left; width: 70%;">
</ng-select>
code1
  • 8,351
  • 8
  • 27
  • 31
  • You're using AngularJS (1.x) in your Angular 2. Check out this question for the proper format of a select with options: https://stackoverflow.com/questions/35945001/binding-select-element-to-object-in-angular-2 – Z. Bagley Aug 22 '17 at 14:55
  • You mean to say is compatible with AngularJS(1.x) and not with Angular 2. – code1 Aug 22 '17 at 15:15
  • That's correct. Angular (2+) uses a different model. – Z. Bagley Aug 22 '17 at 15:17
  • But I see in github projects, even angular 4 is using ng-select. https://github.com/basvandenberg/ng-select/ – code1 Aug 22 '17 at 15:38
  • I mean it's not native to Angular (2+). There are a lot of imitations (either directives or full modules) to recreate the older usage. Have you imported one of these into your project? – Z. Bagley Aug 22 '17 at 15:45

1 Answers1

0

Try this:

<ng-select 
           [items]="tests"
            [(ngModel)]='selected'
           (change)="updateSelected(selected)"
           [active]="selectChannel"
           id="channelList{{tabId}}"
           style="float: left; width: 70%;">
</ng-select>

Here, selected is a variable you have to declare in the .ts file.

sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40
Ram
  • 65
  • 8