valor-software / ng2-select

Angular based replacement for select boxes
http://valor-software.github.io/ng2-select/
MIT License
676 stars 588 forks source link

Using ng2-select-compat in angular 4 application, works fine, but when I add [multiple]="true", the drop down list is not populating. #910

Open chaitrashivanand opened 6 years ago

chaitrashivanand commented 6 years ago

Using ng2-select-compat in angular 4 application, works fine, but when I add [multiple]="true", the drop down list is not populating.

My ts code is as follows: export class DataComponent implements OnInit { testss: TestOption[] = [];

constructor() {
    this.testss.push({ id: "cool1", text: "cool2" });
    this.testss.push({ id: "cool3", text: "cool4" });
}

ngOnInit() {
    }
}

My html code is: <ng-select [items]="testss">

This works fine But if I add multiple like <ng-select [items]="testss" [multiple]="true"> It's not loading the dropdown values.

Newan commented 6 years ago

add css file to your project

alexbulyha commented 6 years ago

Hey chaisangam! I had the same issue and I fixed it by not pushing into the existing array, but instead creating a new array, pushing into the new one, and then assigning the new one to the old:

let newTest: TestOption[] = []; newTest.push({ id: "cool1", text: "cool2" }); newTest.push({ id: "cool3", text: "cool4" }); this.testss = newTest;