0

How do I pass an item on change?

I got this far:

<select #sel (change)="select.emit(sel.value.url)"> <option *ngFor="let item of selectlist"> {{item.description}} </option> </select> 

But I would like to get the "item" passed back on change.

I should get back just the item object

{ value: 0, description: 'Home', url: 'http://www.color.com' }

but instead I get 'Home'.

Here is my Full array

public pagelist:Array<Object> = [ { value: 0, description: 'Home', url: 'http://www.color.com' }, { value: 1, description: 'Tours', subpage: [{ value: 0, description: 'Italy' }, { value: 0, description: 'France' }, { value: 0, description: 'London' }] }, { value: 1, description: 'About us', url: 'http://www.color.com' }, { value: 1, description: 'Contact us', url: 'http://www.color.com' } ]; 

1 Answer 1

1

Replace your code with :

<select #sel (change)="select.emit(selectlist[$event.target.value])"> <option [value]='i' *ngFor="let item of selectlist; let i = index;"> {{item.description}} </option> </select> 
Sign up to request clarification or add additional context in comments.

5 Comments

that get's me the value but I want the Item obj.
@ChrisTarasovs , please check it now
Do you have plunker for this ?
aaa it did work. You can also write it shorter (change)="select.emit(selectlist[sel.value]
yeah you have also added the local varible , will you please upvote my answer then ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.