{"id":3150,"date":"2024-03-25T00:26:22","date_gmt":"2024-03-24T23:26:22","guid":{"rendered":"https:\/\/nguenkam.com\/blog\/?p=3150"},"modified":"2024-03-25T00:26:22","modified_gmt":"2024-03-24T23:26:22","slug":"understanding-the-concept-of-micro-frontend-with-angular","status":"publish","type":"post","link":"https:\/\/nguenkam.com\/blog\/index.php\/2024\/03\/25\/understanding-the-concept-of-micro-frontend-with-angular\/","title":{"rendered":"Understanding the concept of Micro-Frontend  (with Angular)"},"content":{"rendered":"\n<p>Frontend technology is evolving rapidly, presenting a challenge of choosing the right one due to their pros and cons. We tend to opt for technologies with minimal risk and maximum benefits. However, what if we could utilize various technologies for different services?<\/p>\n\n\n\n<p>Micro frontends are an architectural approach to building web applications where a single frontend is composed of multiple smaller, independently deployable applications. This concept draws inspiration from microservices. It involves breaking down large frontend monoliths into smaller, more manageable pieces. Each micro frontend is then responsible for a specific feature or functionality within the larger application.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" src=\"https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2024\/03\/image.png\" alt=\"\" class=\"wp-image-3151\" width=\"555\" height=\"537\" srcset=\"https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2024\/03\/image.png 626w, https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2024\/03\/image-300x290.png 300w, https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2024\/03\/image-24x24.png 24w\" sizes=\"(max-width: 555px) 100vw, 555px\" \/><\/figure><\/div>\n\n\n\n<p class=\"has-text-align-left\"><em><span class=\"has-inline-color has-vivid-cyan-blue-color\">Each team takes charge of a particular specialized part. Micro frontends offer a fresh approach to constructing and scaling frontend apps.<\/span><\/em><\/p>\n\n\n\n<p>This approach brings several advantages:<\/p>\n\n\n\n<ol><li><strong>Independent Development and Deployment<\/strong>: With micro frontends, teams can work on different parts of the application independently. This allows for faster development cycles and easier deployment of changes.<\/li><li><strong>Technology Agnostic:<\/strong> Micro frontends allow teams to use different technologies and frameworks for different parts of the application. This flexibility enables teams to choose the best tool for the job.<\/li><li><strong>Scalability: <\/strong>Micro frontends make it easier to scale development teams as the application grows. New teams can be added to work on new features without impacting existing teams.<\/li><li><strong>Isolation and Resilience: <\/strong>Each micro frontend is isolated from the others, which helps in containing failures and preventing them from affecting the entire application.<\/li><\/ol>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>PS:<\/strong> <em><span class=\"has-inline-color has-vivid-cyan-blue-color\">To sum it all up, we said above that micro-frontends in Angular involve breaking down a large Angular application into smaller, independently deployable applications, each responsible for a specific functionality. This architectural approach allows teams to work independently on different parts of the application, use different technologies for different parts, and scale development more efficiently.<\/span><\/em><\/p>\n\n\n\n<h4>Schema Illustration:<\/h4>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"341\" height=\"150\" src=\"https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2024\/03\/image-1.png\" alt=\"\" class=\"wp-image-3152\" srcset=\"https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2024\/03\/image-1.png 341w, https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2024\/03\/image-1-300x132.png 300w\" sizes=\"(max-width: 341px) 100vw, 341px\" \/><\/figure><\/div>\n\n\n\n<p>In the schema above, the main Angular application is composed of two micro frontends. Each micro frontend contains a specific component, with one being an Angular component and the other being a Vue.js component.<\/p>\n\n\n\n<h4>Code Example:<\/h4>\n\n\n\n<p>Here&#8217;s a simplified code example demonstrating the concept of micro frontends and mixing Angular with Vue.js in a single application:<\/p>\n\n\n\n<ul><li><span class=\"has-inline-color has-vivid-cyan-blue-color\"><strong>Angular Micro Frontend Component:<\/strong><\/span><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ angular-component.component.ts\r\nimport { Component } from '@angular\/core';\r\n\r\n@Component({\r\n  selector: 'app-angular-component',\r\n  template: '&lt;h1>This is an Angular Micro Frontend&lt;\/h1>',\r\n})\r\nexport class AngularComponent {}\r\n<\/code><\/pre>\n\n\n\n<ul><li><strong><span class=\"has-inline-color has-vivid-cyan-blue-color\">Vue.js Micro Frontend Component:<\/span><\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ vue-component.vue\r\n&lt;template>\r\n  &lt;div>\r\n    &lt;h1>This is a Vue.js Micro Frontend&lt;\/h1>\r\n  &lt;\/div>\r\n&lt;\/template>\r\n\r\n&lt;script>\r\nexport default {\r\n  name: 'VueComponent'\r\n}\r\n&lt;\/script>\r\n<\/code><\/pre>\n\n\n\n<ul><li><strong><span class=\"has-inline-color has-vivid-cyan-blue-color\">Integration in Main Angular App:<\/span><\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ main.ts (Angular)\r\nimport { enableProdMode } from '@angular\/core';\r\nimport { platformBrowserDynamic } from '@angular\/platform-browser-dynamic';\r\nimport { AppModule } from '.\/app\/app.module';\r\nimport { createCustomElement } from '@angular\/elements';\r\nimport { AngularComponent } from '.\/angular-component.component';\r\nimport VueComponent from '.\/vue-component.vue';\r\n\r\nenableProdMode();\r\n\r\nplatformBrowserDynamic().bootstrapModule(AppModule)\r\n  .then(moduleRef => {\r\n    const angularElement = createCustomElement(AngularComponent, { injector: moduleRef.injector });\r\n    customElements.define('angular-component', angularElement);\r\n\r\n    const vueElement = createCustomElement(VueComponent, { injector: moduleRef.injector });\r\n    customElements.define('vue-component', vueElement);\r\n  })\r\n  .catch(err => console.error(err));\r\n<\/code><\/pre>\n\n\n\n<p>By following this approach, we can implement micro frontends in Angular and mix technologies like Angular and Vue.js within a single application.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Frontend technology is evolving rapidly, presenting a challenge of choosing the right one due to their pros and cons. We tend to opt for technologies with minimal risk and maximum benefits. However, what if we could utilize various technologies for different services? Micro frontends are an architectural approach to building web applications where a single [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3153,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,37],"tags":[811,812,813],"_links":{"self":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3150"}],"collection":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=3150"}],"version-history":[{"count":1,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3150\/revisions"}],"predecessor-version":[{"id":3154,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3150\/revisions\/3154"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media\/3153"}],"wp:attachment":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=3150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=3150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=3150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}