Code2night
  • Home
  • Guest Posts
  • Tutorial
  • Languages
  • Post Blog
  • Tools
    • JSON Beautifier
    • HTML Beautifier
    • XML Beautifier
    • CSS Beautifier
    • JS Beautifier
    • PDF Editor
    • Word Counter
    • Base64 Encode/Decode
    • Diff Checker
    • JSON to CSV
    • Password Generator
  • Register
  • Login
  1. Home
  2. Blogpost

Angular Material Select Dropdown with Image

Date- Dec 13,2022

8226

Free Download Pay & Download

Step 1: Create New App

 ng new app-material 

Step 2: Add Material Design

Now you have to install the material library in the angular app. So, we can use angular material components:

 ng add @angular/material

Step 3: Import Module

first, we need to import MatFormFieldModule and MatSelectModule. so let's update app.module.ts.

Let's follow the steps:

src/app/app.module.ts

 import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { FormsModule } from '@angular/forms';
import { MatSelectModule, MatFormFieldModule } from '@angular/material';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { DropdownComponent } from './dropdown/dropdown.component';

@NgModule({
  declarations: [
    AppComponent,
    DropdownComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule,
    MatSelectModule,
    MatFormFieldModule,
    BrowserAnimationsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Step 4: Create a new component

ng g c dropdown   

Here, you have to update the HTML template file as below:

src/app/dropdown.component.html

<div class="container">
    <h4>Angular Material Select with Image Example</h4>

    <mat-form-field appearance="fill">
        <mat-select placeholder="Select Categories">
            <mat-option *ngFor="let category of categories" [value]="category.id">
                <img with="20" height="20" [src]="category.image">
                {{category.value}}
            </mat-option>
        </mat-select>
    </mat-form-field>
</div>

Step 5: Update Ts File

Here, you have to update the ts file as below:

src/app/dropdown.component.ts

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

interface Category {
  id: string;
  value: string;
  image: string;
}

@Component({
  selector: 'app-dropdown',
  templateUrl: './dropdown.component.html',
  styleUrls: ['./dropdown.component.scss']
})
export class DropdownComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
  }
  categories: Category[] = [
    { id: '1', value: 'JS', image: 'https://www.itsolutionstuff.com/category-images/javascript.svg' },
    { id: '2', value: 'Git', image: 'https://www.itsolutionstuff.com/category-images/git.png' },
    { id: '3', value: 'Laravel', image: 'https://www.itsolutionstuff.com/category-images/laravel.svg' },
    { id: '4', value: 'Bootstrap', image: 'https://www.itsolutionstuff.com/category-images/bootstrap.svg' },
    { id: '5', value: 'Angular', image: 'https://www.itsolutionstuff.com/category-images/angular.svg' },

  ];
}

Here, you have to update the app.component.html file as below:

we have to call the dropdown component in the app component 

<app-dropdown></app-dropdown>

Run Angular App:

All the required steps have been done, now you have to type the given below command and hit enter to run the Angular app:

 ng serve --open

Now, Go to your web browser, type the given URL and view the app output:

 http://localhost:4200

Output


S
Shubham Batra
Programming author at Code2Night โ€” sharing tutorials on ASP.NET, C#, and more.
View all posts โ†’

Comments

Tags

AspNet
C#
programming
AspNet MVC
c programming
AspNet Core
C
software development
tutorial
MVC
memory management
Paypal
coding
coding best practices
data structures
programming tutorial
tutorials
object oriented programming
Slick Slider
StripeNet
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1760
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp Join Us On Facebook
Code2Night

A community platform for sharing programming knowledge, tutorials, and blogs. Learn, write, and grow with developers worldwide.

Panipat, Haryana, India
info@code2night.com
Quick Links
  • Home
  • Blogs
  • Tutorials
  • About Us
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Guest Posts
Free Dev Tools
  • JSON Beautifier
  • HTML Beautifier
  • CSS Beautifier
  • JS Beautifier
  • Password Generator
  • QR Code Generator
  • Hash Generator
  • Diff Checker
  • Base64 Encode/Decode
  • Word Counter
By Language
© 2026 Code2Night. All Rights Reserved.
Made with for developers  |  Privacy  ยท  Terms
Translate Page