PeterStaev / NativeScript-Drop-Down

A NativeScript DropDown widget.
Apache License 2.0
105 stars 65 forks source link

ngModel should be directly connected to the selected value, not index #132

Closed erkanarslan closed 6 years ago

erkanarslan commented 6 years ago

This is just a suggestion.

ngModel watches the index of the item. Because of that, when user selects a value we need to listen to index change event and get that item by its index. A better solution would be directly watching the value. That way, we don't have to listen to change event, find the item and assign it to the variable.

PeterStaev commented 6 years ago

Hey @erkanarslan , this is because the DropDown does not enforce the use of ValueList. It can be bound to either a simple array or an ObservableArray and there is no value there. Moreover this is how it works in plain Nativescript. So this will not be changed and you will have to work with the index to get the value and populate it in your model.

erkanarslan commented 6 years ago

@PeterStaev It doesn't matter what kind of list you use. You can use the value inside simple array or ObservableArray for ngModel like how you do in web development with select element.

PeterStaev commented 6 years ago

@erkanarslan that is true but in the NativeScript ecosystem everything is based on indexes. For example the ListPicker functions similarly.