{"id":1439,"date":"2023-09-13T05:00:00","date_gmt":"2023-09-13T12:00:00","guid":{"rendered":"https:\/\/www.angulartraining.com\/daily-newsletter\/?p=1439"},"modified":"2023-09-19T14:11:05","modified_gmt":"2023-09-19T21:11:05","slug":"migrating-angular-material-to-v15","status":"publish","type":"post","link":"https:\/\/www.angulartraining.com\/daily-newsletter\/migrating-angular-material-to-v15\/","title":{"rendered":"Migrating Angular Material to v15+"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>This is a guest post by Duncan Faulkner. You can read his first post on&nbsp;<a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/getting-started-with-angular-material\/\" target=\"_blank\" rel=\"noreferrer noopener\">Angular Material here<\/a>. This is the third and final post in this series.<\/p>\n<\/blockquote>\n\n\n\n<p>Note: This post will cover upgrading to Angular Material version 15 from Angular Material 14\u2014all changes affected version 15. Once the migration to Angular Material 15 is complete, migration to Angular Material 16 is straightforward.<\/p>\n\n\n\n<p>The team at Angular Material has created a schema that will do all the heavy lifting when migrating to the <a href=\"https:\/\/m2.material.io\/develop\/web\/guides\/migrating-from-mdl\" target=\"_blank\" rel=\"noopener\" title=\"\">new MDC format<\/a>.<\/p>\n\n\n\n<p>To upgrade your application to version 15<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">ng<\/span> <span class=\"hljs-selector-tag\">update<\/span> <span class=\"hljs-keyword\">@angular<\/span>\/material<span class=\"hljs-keyword\">@15<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>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.<\/p>\n\n\n\n<p>Once your project has upgraded, you can now run the migration tool. This will migrate from the legacy to the new MDC format.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">ng generate @angular\/material:mdc-migration<\/code><\/span><\/pre>\n\n\n<p>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.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\"><span class=\"hljs-comment\">\/\/ TODO(mdc-migration):...<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>It&#8217;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.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Legacy components<\/h2>\n\n\n\n<p>Currently, the Angular Material library includes all the legacy components. If you&#8217;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:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">import<\/span> {\n  MatLegacySliderModule,\n} <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@angular\/material\/legacy-slider'<\/span>;\n\n@Component({\n  <span class=\"hljs-attr\">selector<\/span>: <span class=\"hljs-string\">'slider-formatting-example'<\/span>,\n  <span class=\"hljs-attr\">templateUrl<\/span>: <span class=\"hljs-string\">'slider-formatting-example.html'<\/span>,\n  <span class=\"hljs-attr\">styleUrls<\/span>: &#91;<span class=\"hljs-string\">'slider-formatting-example.css'<\/span>],\n  <span class=\"hljs-attr\">standalone<\/span>: <span class=\"hljs-literal\">true<\/span>,\n  <span class=\"hljs-attr\">imports<\/span>: &#91;MatLegacySliderModule],\n})\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">SliderFormattingExample<\/span> <\/span>{ \n    ...\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>Please note:<\/strong> The legacy versions are currently marked as deprecated and will be removed in version 17 of Angular Material.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a guest post by Duncan Faulkner. You can read his first post on&nbsp;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\u2014all changes affected version 15. Once the migration to Angular Material 15 is complete, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,35],"tags":[],"class_list":["post-1439","post","type-post","status-publish","format-standard","hentry","category-angular","category-material"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1439","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/comments?post=1439"}],"version-history":[{"count":2,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1439\/revisions"}],"predecessor-version":[{"id":1516,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1439\/revisions\/1516"}],"wp:attachment":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/media?parent=1439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/categories?post=1439"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/tags?post=1439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}