diff --git a/vuepress/docs/next/tutorials/create/mfe/angular.md b/vuepress/docs/next/tutorials/create/mfe/angular.md index 116dcc34ca..727150b4b9 100644 --- a/vuepress/docs/next/tutorials/create/mfe/angular.md +++ b/vuepress/docs/next/tutorials/create/mfe/angular.md @@ -3,54 +3,68 @@ sidebarDepth: 2 --- # Create an Angular Micro Frontend +This tutorial describes the process of building an Angular widget on Entando. It creates a docker-based bundle using the ent bundle CLI tool, which is the standard method starting with Entando 7.1. -::: warning Prerequisites -- [A working instance of Entando.](../../../docs/getting-started/README.md) -::: +Git-based bundles are also supported and to follow this tutorial in that format, see this [Angular tutorial](../../../../v7.0/tutorials/create/mfe/angular.md). -::: warning Tested Versions -node v13.8.0 → We suggest using [nvm](https://github.com/nvm-sh/nvm) to handle node installations. -::: +## Prerequisites +* [A working instance of Entando.](../../../docs/getting-started/README.md) -## Create Angular App +* node v13.8.0: Use [nvm](https://github.com/nvm-sh/nvm) to handle node installations. -Install Angular CLI. +## Initialize your Bundle Project +1. To initialize your project, give it a name and build the scaffolding. This name will be used for the default bundle Docker image. +```sh +ent bundle init YOUR-BUNDLE +``` +2. Change to the bundle directory: +```sh +cd YOUR-BUNDLE +``` -``` bash -npm install -g @angular/cli +3. Add the first MFE with the name `angular-widget`: +```sh +ent bundle mfe add angular-widget ``` -Generate a new angular application. +## Create the Angular MFE -``` bash -ng new angular-widget +1. Navigate into the `microfrontends` directory: +```sh +cd microfrontends ``` -Choose the following options: +2. Install the Angular CLI: ``` bash -? Would you like to add Angular routing? No -? Which stylesheet format would you like to use? CSS +npm install -g @angular/cli ``` -Serve the application. +3. Generate a new Angular application: ``` bash -cd angular-widget +ng new angular-widget ``` +4. Choose the following options: + ``` bash -ng serve +? Would you like to add Angular routing? `No` +? Which stylesheet format would you like to use? `CSS` ``` -This is the expected output: +5. From the `angular-widget` directory, serve the application: + + ``` bash + cd angular-widget + ng serve + ``` + + This is the expected output: angular-widget - ├── e2e - │ └── src - │ ├── app.e2e-spec.ts - │ └── app.po.ts - │ + ├── .angular + ├── .vscode ├── node_modules ├── src │ ├── app @@ -74,87 +88,82 @@ This is the expected output: │ ├── styles.css │ └── test.ts │ + ├── .browserlistrc ├── .editorconfig ├── .gitignore ├── angular.json - ├── browserlist ├── karma.conf.js ├── package.json + ├── package-lock.json ├── README.md ├── tsconfig.app.json ├── tsconfig.json - ├── tsconfig.spec.json - └── tslint.json + └── tsconfig.spec.json + -### Convert to Custom Element - -Next, let's convert our Angular app into a custom element. We'll use [Angular elements](https://angular.io/guide/elements) to transform components into custom elements. +### Configure the Custom Element +Next, convert the Angular widget into a custom element, using [Angular elements](https://angular.io/guide/elements) to transform components into custom elements. +1. Install the Angular elements ``` bash ng add @angular/elements ``` +[Angular elements](https://angular.io/guide/elements) are Angular components packaged as custom elements, a web standard for defining new HTML elements independent of any framework. ::: warning -Install the Angular elements package using `ng add`, not with `npm install` as it runs additional steps behind the scenes like adding the `document-register-element` polyfill. +Install the Angular elements package using `ng add` (not with `npm install` as it runs additional steps behind the scenes). ::: -::: tip -[Angular elements are Angular components packaged as custom elements (also called Web Components), a web standard for defining new HTML elements in a framework-agnostic way.](https://angular.io/guide/elements) -::: - -Open `angular-widget/src/app/app.module.ts`. - -- Here's what the initial file looks like: - -``` js -import { BrowserModule } from '@angular/platform-browser'; -import { NgModule } from '@angular/core'; - -import { AppComponent } from './app.component'; - -@NgModule({ - declarations: [ - AppComponent - ], - imports: [ - BrowserModule - ], - providers: [], - bootstrap: [AppComponent] -}) -export class AppModule { } -``` - -Replace the entire file with: - -``` js -import { BrowserModule } from '@angular/platform-browser'; -import { NgModule, Injector } from '@angular/core'; -import { createCustomElement } from '@angular/elements'; -import { AppComponent } from './app.component'; - -@NgModule({ - declarations: [ - AppComponent - ], - imports: [ - BrowserModule - ], - providers: [], - entryComponents: [AppComponent] -}) -export class AppModule { - constructor(private injector: Injector) {} - - ngDoBootstrap() { - const el = createCustomElement(AppComponent, { injector: this.injector }); - customElements.define('angular-widget', el); - } -} -``` - -1. In the initial file, `AppModule` is bootstrapped directly during application launch. -2. In the updated file, we booststrap our custom element using the [`ngDoBootstrap()` method](https://angular.io/guide/entry-components). +2. Open `angular-widget/src/app/app.module.ts`. Here's what the initial file looks like: + + ``` js + import { BrowserModule } from '@angular/platform-browser'; + import { NgModule } from '@angular/core'; + + import { AppComponent } from './app.component'; + + @NgModule({ + declarations: [ + AppComponent + ], + imports: [ + BrowserModule + ], + providers: [], + bootstrap: [AppComponent] + }) + export class AppModule { } + ``` + +3. Replace the entire file with: + + ```js + import { BrowserModule } from '@angular/platform-browser'; + import { NgModule, Injector } from '@angular/core'; + import { createCustomElement } from '@angular/elements'; + import { AppComponent } from './app.component'; + + @NgModule({ + declarations: [ + AppComponent + ], + imports: [ + BrowserModule + ], + providers: [], + entryComponents: [AppComponent] + }) + export class AppModule { + constructor(private injector: Injector) {} + + ngDoBootstrap() { + const el = createCustomElement(AppComponent, { injector: this.injector }); + customElements.define('angular-widget', el); + } + } + ``` + + In the original file, `AppModule` is bootstrapped directly during the application launch. In the updated file, the custom element is bootstrapped using the [`ngDoBootstrap()` method](https://angular.io/guide/entry-components). ::: warning Custom Elements - [Must contain a hyphen `-` in the name.](https://stackoverflow.com/questions/22545621/do-custom-elements-require-a-dash-in-their-name): @@ -162,157 +171,88 @@ export class AppModule { - Should follow `kebab-case` for naming convention. ::: -### Test Micro Frontend - -Now, let's check our custom element to see if it's working. - -Open `angular-widget/src/index.html`. - -In the `
`, replace `