How do I get the value from the select option in Angular 4?
I want to assign it to a new variable in the component.ts file. I\'ve tried this but outputs nothing.
As a general (see Stackblitz here: https://stackblitz.com/edit/angular-gh2rjx):
HTML
Selected option: {{ selectedOption }}
Button output: {{ printedOption }}
Typescript
export class AppComponent {
selectedOption: string;
printedOption: string;
options = [
{ name: "option1", value: 1 },
{ name: "option2", value: 2 }
]
print() {
this.printedOption = this.selectedOption;
}
}
In your specific case you can use ngModel like this:
HelloCorp() {
console.log("My input: ", corporationObj);
}