This is a guest post by Duncan Faulkner. You can read his first post on Angular Material here. This is the third and final post in this series.
Note: This post will cover upgrading to Angular Material version 15 from Angular Material 14—all changes affected version 15. Once the migration to Angular Material 15 is complete, migration to Angular Material 16 is straightforward.
The team at Angular Material has created a schema that will do all the heavy lifting when migrating to the new MDC format.
To upgrade your application to version 15
ng update @angular/material@15
Code language: CSS (css)
This will automatically run the migration schema and move your project over to use the legacy version, ensuring that your application continues to run with minimal changes.
Once your project has upgraded, you can now run the migration tool. This will migrate from the legacy to the new MDC format.
ng generate @angular/material:mdc-migration
This will update your project, including TypeScript, styles, and templates, as much as possible. Where it cannot update your code, the migration tool will insert comments into your code for a developer to fix.
// TODO(mdc-migration):...
Code language: JSON / JSON with Comments (json)
It’s also possible to migrate parts of your application; this can be a single component or a range of components, and the migration script will prompt the directory and components to migrate.
The migration to MDC is a welcoming and positive step. It improves accessibility, adheres to the Material Design Specification, and allows better adoption of future specification versions.
Legacy components
Currently, the Angular Material library includes all the legacy components. If you’re not able to upgrade to the latest version and want to continue to use these legacy components, you need to import the legacy module, for example:
import {
MatLegacySliderModule,
} from '@angular/material/legacy-slider';
@Component({
selector: 'slider-formatting-example',
templateUrl: 'slider-formatting-example.html',
styleUrls: ['slider-formatting-example.css'],
standalone: true,
imports: [MatLegacySliderModule],
})
export class SliderFormattingExample {
...
}
Code language: JavaScript (javascript)
Please note: The legacy versions are currently marked as deprecated and will be removed in version 17 of Angular Material.