Angular 2 select option (dropdown) - how to get the value on change so it can be used in a function?

前端 未结 6 919
小蘑菇
小蘑菇 2020-12-13 17:49

I am trying to build a drop down with a few values.

However, on selecting a value, I want to make an API call that takes an id.

In my component.ts, I have an

6条回答
  •  情书的邮戳
    2020-12-13 18:19

    Another solution would be,you can get the object itself as value if you are not mentioning it's id as value: Note: [value] and [ngValue] both works here.

    
    

    In ts:

    your_method(v:any){
      //access values here as needed. 
      // v.id or v.name
    }
    

    Note: If you are using reactive form and you want to catch selected value on form Submit, you should use [ngValue] directive instead of [value] in above scanerio

    Example:

      
    

    In ts:

    form_submit_method(){
            let v : any = this.form_group_name.value.form_control_name;  
        }
    

提交回复
热议问题