<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mohd Irshad</title>
    <description>The latest articles on DEV Community by Mohd Irshad (@mohd_irshad_9f988211f893a).</description>
    <link>https://dev.to/mohd_irshad_9f988211f893a</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2097339%2Faa41f1ea-2de1-471c-b409-6bdce19360a5.jpeg</url>
      <title>DEV Community: Mohd Irshad</title>
      <link>https://dev.to/mohd_irshad_9f988211f893a</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mohd_irshad_9f988211f893a"/>
    <language>en</language>
    <item>
      <title>UPGRADE to Angular Material v15 with MDC</title>
      <dc:creator>Mohd Irshad</dc:creator>
      <pubDate>Thu, 16 Jan 2025 17:32:29 +0000</pubDate>
      <link>https://dev.to/mohd_irshad_9f988211f893a/upgrade-to-angular-material-v15-with-mdc-2a22</link>
      <guid>https://dev.to/mohd_irshad_9f988211f893a/upgrade-to-angular-material-v15-with-mdc-2a22</guid>
      <description>&lt;p&gt;&lt;strong&gt;Upgrading Angular Material from Version 14 to 15: A Step-by-Step Guide&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you're planning to upgrade Angular Material from version 14 to version 15, follow these essential steps to prepare and execute the migration. Before upgrading, some adjustments in your existing codebase are necessary to avoid breaking changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Preparatory Steps in Angular Material v14&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;1. Update&lt;/strong&gt; floatLabel &lt;strong&gt;Property&lt;/strong&gt;&lt;br&gt;
The floatLabel="never" value is deprecated in Angular Material v15. Replace it with a valid value such as floatLabel="always" or the default floatLabel="auto".&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;mat-form-field class="text-class" floatLabel="never"&amp;gt;
  &amp;lt;input/&amp;gt;
&amp;lt;/mat-form-field&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;After:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;mat-form-field class="text-class" floatLabel="always"&amp;gt;
  &amp;lt;input/&amp;gt;
&amp;lt;/mat-form-field&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Update&lt;/strong&gt; appearance &lt;strong&gt;Property&lt;/strong&gt;&lt;br&gt;
The appearance="standard" value is no longer supported. Replace it with either appearance="fill" or appearance="outline".&lt;br&gt;
&lt;strong&gt;Before:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;mat-form-field class="field-body" appearance="standard" floatLabel="always"&amp;gt;
  &amp;lt;input/&amp;gt;
&amp;lt;/mat-form-field&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;After:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;mat-form-field class="field-body" appearance="fill" floatLabel="always"&amp;gt;
  &amp;lt;input/&amp;gt;
&amp;lt;/mat-form-field&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Update&lt;/strong&gt; mat-tab-nav-bar &lt;strong&gt;to Use&lt;/strong&gt; tabPanel&lt;br&gt;
&lt;strong&gt;Before:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="nav"&amp;gt;
  &amp;lt;nav mat-tab-nav-bar&amp;gt;
    &amp;lt;ng-container *ngFor="let item of items"&amp;gt;
      &amp;lt;span&amp;gt;{{ item }}&amp;lt;/span&amp;gt;
    &amp;lt;/ng-container&amp;gt;
  &amp;lt;/nav&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;After:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="nav"&amp;gt;
  &amp;lt;nav mat-tab-nav-bar [tabPanel]="tabPanel"&amp;gt;
    &amp;lt;ng-container *ngFor="let item of items"&amp;gt;
      &amp;lt;span&amp;gt;{{ item }}&amp;lt;/span&amp;gt;
    &amp;lt;/ng-container&amp;gt;
  &amp;lt;/nav&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;mat-tab-nav-panel #tabPanel&amp;gt;
  &amp;lt;router-outlet&amp;gt;&amp;lt;/router-outlet&amp;gt;
&amp;lt;/mat-tab-nav-panel&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;By completing these three steps, you can avoid breaking template errors when upgrading to Angular Material v15.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Upgrade Angular Material to v15&lt;br&gt;
Run the following command to upgrade Angular Material to version 15:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @angular/material@^15.2.9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;update other packages too in your application as required.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Migrate to MDC-Based Components&lt;/strong&gt;&lt;br&gt;
Angular Material v15 officially transitions to &lt;strong&gt;MDC-based components&lt;/strong&gt;, which adhere strictly to Material Design specifications. Non-MDC components are deprecated and will no longer receive updates or fixes. To migrate:&lt;br&gt;
&lt;strong&gt;1. Run the Migration Tool&lt;/strong&gt;&lt;br&gt;
The Angular CLI provides a schematic to migrate your project to MDC-based components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng generate @angular/material:mdc-migration
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Update Your Theme&lt;/strong&gt;&lt;br&gt;
MDC-based components use an updated theming API. Replace your old theme configuration with the new structure:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before (v14 or earlier):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$custom-typography: mat.define-typography-config(
  $font-family: 'Noto Sans',
  $body-1: mat.define-typography-level($font-size-xs, $line-height-xs, $font-weight-regular),
  $body-2: mat.define-typography-level($font-size-xs, $line-height-xs, $font-weight-bold),
  $caption: mat.define-typography-level($font-size-xxs, $line-height-xxs, $font-weight-regular),
  $button: mat.define-typography-level($font-size-xs, $line-height-xs, $font-weight-regular)
);

@include mat.core($custom-typography);

$theme-primary: mat.define-palette($custom-pink);
$theme-accent: mat.define-palette($custom-wine);
$theme-warn: mat.define-palette(mat.$red-palette);

$theme: mat.define-light-theme($theme-primary, $theme-accent, $theme-warn);

@include mat.all-component-themes($theme);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;After (v15 with MDC):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$custom-typography: mat.define-typography-config(
  $font-family: 'Noto Sans',
  $body-1: mat.define-typography-level($font-size-xs, $line-height-xs, $font-weight-regular),
  $body-2: mat.define-typography-level($font-size-xs, $line-height-xs, $font-weight-bold),
  $caption: mat.define-typography-level($font-size-xxs, $line-height-xxs, $font-weight-regular),
  $button: mat.define-typography-level($font-size-xs, $line-height-xs, $font-weight-regular)
);

@include mat.core();

$theme-primary: mat.define-palette($custom-pink);
$theme-accent: mat.define-palette($custom-wine);
$theme-warn: mat.define-palette(mat.$red-palette);

$theme: mat.define-light-theme(
  (
    color: (
      primary: $theme-primary,
      accent: $theme-accent,
      warn: $theme-warn
    ),
    typography: $custom-typography,
    density: 0
  )
);

@include mat.all-component-themes($theme);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Post-Migration Adjustments&lt;/strong&gt;&lt;br&gt;
The migration tool (ng generate @angular/material:mdc-migration) does not update all class names automatically. You'll need to manually update class names in your styles where necessary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
Pre-v15: mat-form-field-flex&lt;br&gt;
Post-v15 with MDC: mat-mdc-form-field-flex&lt;br&gt;
To identify required changes, look for // TODO (mdc-migration) comments in your SCSS files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Migrate to MDC-Based Components?&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Future-Proof&lt;/strong&gt;: Non-MDC components are no longer maintained.&lt;br&gt;
&lt;strong&gt;Material Design Compliance&lt;/strong&gt;: MDC-based components adhere strictly to Material Design guidelines.&lt;br&gt;
&lt;strong&gt;Improved Performance&lt;/strong&gt;: MDC components include accessibility improvements, better animations, and updated styles.&lt;br&gt;
&lt;strong&gt;Avoid Forced Migration Later&lt;/strong&gt;: Future Angular Material versions will remove non-MDC components entirely.&lt;br&gt;
For a comprehensive list of changes, consult the official &lt;a href="https://v15.material.angular.io/guide/mdc-migration" rel="noopener noreferrer"&gt;Angular Material documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;By following these steps, you can seamlessly upgrade to Angular Material v15 and ensure your application is ready for future updates.&lt;/p&gt;

</description>
      <category>mdc</category>
      <category>fullstack</category>
      <category>webtech</category>
      <category>angular</category>
    </item>
  </channel>
</rss>
