Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kendo angular dropdown setting a value programmatically

Using kendo angular dropdown, I can set the data and default value, but for some reason setting the value later on from the available options does not work?

i have a basic data model of {id:x, value:y}. what is the correct code to set the value after the dropdown was initialized?

using latest version of angular and kendo.

initializing the value with:

public areaModel: {id:number, value: string}

then I tried to set it with:

this.areaModel = {id: data.site.siteId, value: data.site.siteName}

the actual dropdown is:

<kendo-dropdownlist [data]="area" [(ngModel)]="areaModel" [textFIeld]="value" [valueField]="id"></kendo-dropdownlist>

do ignore typo errors since I'm typing this amnually - the code is in a closed system.

also, everything else is working' I can set the data, I can get the selected value.

like image 951
idekkers Avatar asked Oct 27 '25 04:10

idekkers


1 Answers

The correct syntax should be:

<kendo-dropdownlist [data]="area" [(ngModel)]="areaModel" textField="value" valueField="id"></kendo-dropdownlist>

You can also set the value of any kind of Kendo dropdown with the value property. For example with the Kendo dropdownlist, it works like this:

<kendo-dropdownlist [data]='area' formControlName='area' [value]='area[0]'></kendo-dropdownlist>

Of course in this case you have to be sure that there is at least one element in your area array.

I guess you already looked into the documentation for value binding using dropdowns, but just in case, here it is.

like image 51
Matthias Sommer Avatar answered Oct 29 '25 21:10

Matthias Sommer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!