Closed joey0xx closed 7 years ago
Hey @joey0xx , you cant bind the drop down to a custom array. The supported binding sources for the items are the ObservableArray
and the plugin's ValueList
. So you need to map your array to one of those.
@PeterStaev thank you, it was in the documentation I should've made the association to what I was trying to do... I still have a problem because Im trying to use a custom pipe to filter the dropdown by the value
property.
export class VisibilityPipe implements PipeTransform {
transform(items: ValueList<string>) {
return items.filter(item => item.value === "true");
}
}
Its sort of working but its only showing [object Object]
instead of the display
property. I tried doing it like this :
export class VisibilityPipe implements PipeTransform {
transform(items: ValueList<string>): ValueList<any> {
return items.filter(item => item.value === "true");
}
}
But I get an error saying Propert getDisplay is missing in type ValueItem<string>
. My guess its because the pipe is returning Array
instead of ValueList
. Is it possible to make what Im trying to do work?
@joey0xx , you cannot return an array of ValueItem
. You need to use the ValueList
class. So in your pipes from the filtered array you need to create a ValueList
instance using the provided constructor or push()
method.
@PeterStaev Thanks, while it didn't work 100%, with the pipe because that only filtered once when the drop down loads, what I did is filter it every time it closes/opens/loads, push to ValueList and then assign it to items
.
Is there a way to access a property from an array of objects? For example I have this array:
and on the dropdown I want to access the
day
property. Ex:<DropDown [items]="days.day"></DropDown>
I tried using ngFor:
but I get an error saying
cannot read property 'day' of undefined
...