How to add on Change Event on Dropdown in Angular?

How to add on Change Event on Dropdown in Angular?

In this post we will give you information about How to add on Change Event on Dropdown in Angular?. Hear we will give you detail about How to add on Change Event on Dropdown in Angular?And how to use it also give you demo for it if it is necessary.

In this tutorial, i will show you angular dropdown on change event. Here you will learn change event on select box in angular. i explained simply about angular change event on select. Here you will learn change event in dropdown angular. Here, Creating a basic example of get dropdown selected value on change in angular.

You can easily get dropdown selected value on change event in angular 6, angular 7, angular 8 and angular 9.

Here, i will give you very simple example to getting selected option value by change event with reactive form. here we will create one website list dropdown and if you choose anyone then it will by print console selected value on change event. we created changeWebsite() that will call on change of dropdown value. so let’s see app.component.html and app.component.ts file bellow.

So, let’s see example

src/app/app.component.html

<div >

<h1>Angular Select Dropdown Example - ItSolutionStuff.com</h1>

<form [formGroup]="form" (ngSubmit)="submit()">

<div >

<label for="website">Website:</label>

<select formControlName="website" (change)="changeWebsite($event)">

<option disabled>Select Website</option>

<option>Choose Website</option>

<option *ngFor="let web of websiteList">{{web}}</option>

</select>

<div *ngIf="f.website.touched && f.website.invalid" >

<div *ngIf="f.website.errors.required">Name is required.</div>

</div>

</div>

<button type="submit" [disabled]="!form.valid">Submit</button>

</form>

</div>

src/app/app.component.ts

import { Component } from '@angular/core';

import { FormGroup, FormControl, Validators} from '@angular/forms';

@Component({

selector: 'app-root',

templateUrl: './app.component.html',

styleUrls: ['./app.component.css']

})

export class AppComponent {

websiteList: any = ['ItSolutionStuff.com', 'HDTuto.com', 'Nicesnippets.com']

form = new FormGroup({

website: new FormControl('', Validators.required)

});

get f(){

return this.form.controls;

}

submit(){

console.log(this.form.value);

}

changeWebsite(e) {

console.log(e.target.value);

}

}

Output:

ItSolutionStuff.com

I hope it can help you…

Hope this code and post will helped you for implement How to add on Change Event on Dropdown in Angular?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

See also 

PHP - I Can't get the $_POST Values on Ajax Request

In this post we will give you information about PHP - I Can't get the $_POST Values on Ajax Request. Hear we will give you detail about PHP - I Can't get the $_POST Values on Ajax RequestAnd how to use it also give you demo for it if it is necessary.



I want to share this posts with you because when i was working on native PHP and Ajax Post request(Specially AngularJS Post request) at that time i can't get Post value on form submit. That's why i would like to share you this post. I also want to tell you i was working on my Ubuntu 14.04. I did try lot but i can't get value.

At last find stuff to how to solve this issue, i did use "file_get_contents('php://input')" that way i could get POST value in json object and i also decode json value using "json_decode()". So let's try this way :

Example:

$post = file_get_contents('php://input');

$post = json_decode($post);

$sql = "INSERT INTO items (title) VALUES ('".$post->title."')";

$result = $mysqli->query($sql);

Hope this code and post will helped you for implement PHP - I Can't get the $_POST Values on Ajax Request. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

2  +  5  =  

We accept paid advance and paid guest Posting on our Site : Contact US