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

前端 未结 6 923
小蘑菇
小蘑菇 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:21

    Template/HTML File (component.ts)

    
    

    Typescript File (component.ts)

    values = [
      { id: 3432, name: "Recent" },
      { id: 3442, name: "Most Popular" },
      { id: 3352, name: "Rating" }
    ];
    
    onChange(cityEvent){
        console.log(cityEvent); // It will display the select city data
    }
    

    (ngModelChange) is the @Output of the ngModel directive. It fires when the model changes. You cannot use this event without the ngModel directive

提交回复
热议问题