How to get selected value from select component


Rafael Augusto

How to get selected value from select component?

select.component.ts:

export class PfSelectComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

  @Input() options : Array<Object>;

}

select.component.html

<select [(ngModel)]="selectedValue" id="exampleFormControlSelect1" class="form-control">
  <option *ngFor="let option of options" [ngValue]="option.value">{{option.name}}</option>
</select>

select value: {{selectedValue}}

{{selectValue}} does not display the value selected in the component.

Kwon Ji Hoon

select.component.html

You should use [value] instead of [ngValue]: [ngValue] => [value]

<select [(ngModel)]="selectedValue" id="exampleFormControlSelect1" class="form-control" >
  <option *ngFor="let option of options" [value]="option.value">{{option.name}}</option>
</select>

select value: {{selectedValue}}

select.component.ts

and add public selectedValue;

export class PfSelectComponent implements OnInit {

  public selectedValue;
  constructor() { }

  ngOnInit() {
  }

  @Input() options : Array<Object>;
}

I use

options = [
    {
      value: 1,
      name : "1"
    },
    {
      value: 2,
      name : "2"
    },
    {
      value: 3,
      name : "3"
    }
  ]

It works great :)

Related


How to get selected value from select component

Rafael Augusto How to get selected value from select component? select.component.ts: export class PfSelectComponent implements OnInit { constructor() { } ngOnInit() { } @Input() options : Array<Object>; } select.component.html <select [(ngModel)]=

How to get selected value from select component

Rafael Augusto How to get selected value from select component? select.component.ts: export class PfSelectComponent implements OnInit { constructor() { } ngOnInit() { } @Input() options : Array<Object>; } select.component.html <select [(ngModel)]=

How to get selected value from select to another component?

Anaya Dream I have this select component and their values are taken from useEffect data. In this component, I can see in the console fromselect const SelectName = () => { const [value, setValue] = useState(0); const [names, setNames] = useState([]); cons

How to get selected value from <select>

blow I try to get value from select area using form and $_Post. I've browsed through many older questions, and sure enough, I followed the directions. Still I get the error: Undefined array key 'platform'. <form action="" method="POST"> <select name="

How to get selected value from <select>

blow I try to get value from select area using form and $_Post. I've browsed through many older questions, and sure enough, I followed the directions. Still I get the error: Undefined array key 'platform'. <form action="" method="POST"> <select name="

How to get selected value from <select>

blow I try to get value from select area using form and $_Post. I've browsed through many older questions, and sure enough, I followed the directions. Still I get the error: Undefined array key 'platform'. <form action="" method="POST"> <select name="

Need to get selected option from select component

Sousse I am using Ember components. In that select and button are available. My purpose is to alert the selected option in the select element when the button is clicked. The code is here : http://jsbin.com/uQOWiqIk/1/edit In the code, the component is repeated

Need to get selected option from select component

Sousse I am using Ember components. In that select and button are available. My purpose is to alert the selected option in the select element when the button is clicked. The code is here : http://jsbin.com/uQOWiqIk/1/edit In the code, the component is repeated

Need to get selected option from select component

Sousse I am using Ember components. In that select and button are available. My purpose is to alert the selected option in the select element when the button is clicked. The code is here : http://jsbin.com/uQOWiqIk/1/edit In the code, the component is repeated

How to get selected value from <oj-select-one>?

Osama Alpha I have an oj-select-one component with the following definition: <oj-select-one id="select1" style="max-width:20em" options={{data3}} value="{{data3.Id}}" options-keys="{{optionKeys2}}" > </oj-sel

How to get selected value from select box in angularjs

Sharmavikram Hello everyone I'm trying to get option value from select box on button click but it shows undefined in console. The option value comes from the server Here is my HTML code <div class="form-group"> <label class="control-form" for="cityid">

How to get selected value from ionic 4 ion-select

Amit Namdeo I am trying to get the selected 'value' from 'ion-select', but when i select any value from 'ion-select', as a newbie to 'ionic 4', i am getting 'indeterminate value' and i can't Sort it yourself. <ion-item> <ion-label>Country</ion-

How to get selected option value from select inside div

zabi I have the following html code <div id="BrokersList4ServiceEndWrapper"> <select id="BrokersList4ServiceEnd"> <option value="1">s1</option> <option value="2">s2</option> </select> </div> I tried Set the selected value to 1. Get the value of the

How to get selected value from ionic 4 ion-select

Amit Namdeo I am trying to get the selected 'value' from 'ion-select', but when i select any value from 'ion-select', as a newbie to 'ionic 4', i am getting 'indeterminate value' and i can't Sort it yourself. <ion-item> <ion-label>Country</ion-

How to get selected option value from select inside div

zabi I have the following html code <div id="BrokersList4ServiceEndWrapper"> <select id="BrokersList4ServiceEnd"> <option value="1">s1</option> <option value="2">s2</option> </select> </div> I tried Set the selected value to 1. Get the value of the

Get value from selected option in web component

devpato I'm trying to get the value of the selected option, so when someone uses my web component, they can access it. I think the problem is related to shadow root __createOptions() { const SELECT = this.shadowRoot.querySelector('select'); SELECT.addE

Get value from selected option in web component

devpato I'm trying to get the value of the selected option, so when someone uses my web component, they can access it. I think the problem is related to shadow root __createOptions() { const SELECT = this.shadowRoot.querySelector('select'); SELECT.addE

Get value from selected option in web component

devpato I'm trying to get the value of the selected option, so when someone uses my web component, they can access it. I think the problem is related to shadow root __createOptions() { const SELECT = this.shadowRoot.querySelector('select'); SELECT.addE

Get value from selected option in web component

devpato I'm trying to get the value of the selected option, so when someone uses my web component, they can access it. I think the problem is related to shadow root __createOptions() { const SELECT = this.shadowRoot.querySelector('select'); SELECT.addE

Get value from selected option in web component

devpato I'm trying to get the value of the selected option, so when someone uses my web component, they can access it. I think the problem is related to shadow root __createOptions() { const SELECT = this.shadowRoot.querySelector('select'); SELECT.addE