Skip to content

Commit 1e28343

Browse files
committed
docs(angular): update tutorial with angular v20 changes
1 parent f117119 commit 1e28343

File tree

121 files changed

+588
-593
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+588
-593
lines changed

docs/shared/tutorials/angular-monorepo.md

Lines changed: 61 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ Let's name the initial application `angular-store`. In this tutorial we're going
6969
│ ├─ angular-store
7070
│ │ ├─ src
7171
│ │ │ ├─ app
72-
│ │ │ │ ├─ app.component.css
73-
│ │ │ │ ├─ app.component.html
74-
│ │ │ │ ├─ app.component.spec.ts
75-
│ │ │ │ ├─ app.component.ts
72+
│ │ │ │ ├─ app.css
73+
│ │ │ │ ├─ app.html
74+
│ │ │ │ ├─ app.spec.ts
75+
│ │ │ │ ├─ app.ts
7676
│ │ │ │ ├─ app.config.ts
7777
│ │ │ │ ├─ app.routes.ts
78-
│ │ │ │ └─ nx-welcome.component.ts
78+
│ │ │ │ └─ nx-welcome.ts
7979
│ │ │ ├─ assets
8080
│ │ │ ├─ index.html
8181
│ │ │ ├─ main.ts
@@ -85,7 +85,6 @@ Let's name the initial application `angular-store`. In this tutorial we're going
8585
│ │ ├─ jest.config.ts
8686
│ │ ├─ project.json
8787
│ │ ├─ tsconfig.app.json
88-
│ │ ├─ tsconfig.editor.json
8988
│ │ ├─ tsconfig.json
9089
│ │ └─ tsconfig.spec.json
9190
│ └─ angular-store-e2e
@@ -153,7 +152,7 @@ Each target contains a configuration object that tells Nx how to run that target
153152
...
154153
"targets": {
155154
"serve": {
156-
"executor": "@angular-devkit/build-angular:dev-server",
155+
"executor": "@angular/build:dev-server",
157156
"defaultConfiguration": "development",
158157
"options": {
159158
"buildTarget": "angular-store:build"
@@ -240,14 +239,13 @@ CREATE apps/inventory/src/favicon.ico
240239
CREATE apps/inventory/src/index.html
241240
CREATE apps/inventory/src/styles.css
242241
CREATE apps/inventory/tsconfig.app.json
243-
CREATE apps/inventory/tsconfig.editor.json
244242
CREATE apps/inventory/tsconfig.json
245-
CREATE apps/inventory/src/app/app.component.css
246-
CREATE apps/inventory/src/app/app.component.html
247-
CREATE apps/inventory/src/app/app.component.spec.ts
248-
CREATE apps/inventory/src/app/app.component.ts
243+
CREATE apps/inventory/src/app/app.css
244+
CREATE apps/inventory/src/app/app.html
245+
CREATE apps/inventory/src/app/app.spec.ts
246+
CREATE apps/inventory/src/app/app.ts
249247
CREATE apps/inventory/src/app/app.config.ts
250-
CREATE apps/inventory/src/app/nx-welcome.component.ts
248+
CREATE apps/inventory/src/app/nx-welcome.ts
251249
CREATE apps/inventory/src/main.ts
252250
CREATE apps/inventory/.eslintrc.json
253251
CREATE apps/inventory/jest.config.ts
@@ -290,9 +288,9 @@ When you develop your Angular application, usually all your logic sits in the `a
290288
│ │ │ ├─ cart
291289
│ │ │ ├─ ui
292290
│ │ │ ├─ ...
293-
│ │ │ └─ app.tsx
291+
│ │ │ └─ app.ts
294292
│ │ ├─ ...
295-
│ │ └─ main.tsx
293+
│ │ └─ main.ts
296294
│ ├─ ...
297295
│ └─ project.json
298296
├─ nx.json
@@ -314,9 +312,9 @@ Nx allows you to separate this logic into "local libraries". The main benefits i
314312
Let's assume our domain areas include `products`, `orders` and some more generic design system components, called `ui`. We can generate a new library for each of these areas using the Angular library generator:
315313

316314
```
317-
npx nx g @nx/angular:library libs/products --standalone
318-
npx nx g @nx/angular:library libs/orders --standalone
319-
npx nx g @nx/angular:library libs/shared/ui --standalone
315+
npx nx g @nx/angular:library libs/products
316+
npx nx g @nx/angular:library libs/orders
317+
npx nx g @nx/angular:library libs/shared/ui
320318
```
321319

322320
Note how we type out the full path in the `directory` flag to place the libraries into a subfolder. You can choose whatever folder structure you like to organize your projects. If you change your mind later, you can run the [move generator](/nx-api/workspace/generators/move) to move a project to a different folder.
@@ -384,51 +382,56 @@ All libraries that we generate automatically have aliases created in the root-le
384382
}
385383
```
386384

387-
Hence we can easily import them into other libraries and our Angular application. As an example, let's use the pre-generated `ProductsComponent` component from our `libs/products` library.
385+
Hence we can easily import them into other libraries and our Angular application. As an example, let's use the pre-generated `Products` component from our `libs/products` library.
388386

389-
You can see that the `ProductsComponent` is exported via the `index.ts` file of our `products` library so that other projects in the repository can use it. This is our public API with the rest of the workspace. Only export what's really necessary to be usable outside the library itself.
387+
You can see that the `Products` is exported via the `index.ts` file of our `products` library so that other projects in the repository can use it. This is our public API with the rest of the workspace. Only export what's really necessary to be usable outside the library itself.
390388

391389
```ts {% fileName="libs/products/src/index.ts" %}
392-
export * from './lib/products/products.component';
390+
export * from './lib/products/products';
393391
```
394392

395393
We're ready to import it into our main application now. First (if you haven't already), let's set up the Angular router. Configure it in the `app.config.ts`.
396394

397-
```ts {% fileName="apps/angular-store/src/app/app.config.ts" highlightLines=[2,3,4,5,6,9] %}
398-
import { ApplicationConfig } from '@angular/core';
395+
```ts {% fileName="apps/angular-store/src/app/app.config.ts" highlightLines=[6,7,13] %}
399396
import {
400-
provideRouter,
401-
withEnabledBlockingInitialNavigation,
402-
} from '@angular/router';
397+
ApplicationConfig,
398+
provideBrowserGlobalErrorListeners,
399+
provideZoneChangeDetection,
400+
} from '@angular/core';
401+
import { provideRouter } from '@angular/router';
403402
import { appRoutes } from './app.routes';
404403

405404
export const appConfig: ApplicationConfig = {
406-
providers: [provideRouter(appRoutes, withEnabledBlockingInitialNavigation())],
405+
providers: [
406+
provideBrowserGlobalErrorListeners(),
407+
provideZoneChangeDetection({ eventCoalescing: true }),
408+
provideRouter(appRoutes),
409+
],
407410
};
408411
```
409412

410-
And in `app.component.html`:
413+
And in `app.html`:
411414

412-
```ts {% fileName="apps/angular-store/src/app/app.component.html" %}
415+
```ts {% fileName="apps/angular-store/src/app/app.html" %}
413416
<router-outlet></router-outlet>
414417
```
415418

416-
Then we can add the `ProductsComponent` component to our `app.routes.ts` and render it via the routing mechanism whenever a user hits the `/products` route.
419+
Then we can add the `Products` component to our `app.routes.ts` and render it via the routing mechanism whenever a user hits the `/products` route.
417420

418421
```ts {% fileName="apps/angular-store/src/app/app.routes.ts" highlightLines=[10,11,12,13,14] %}
419422
import { Route } from '@angular/router';
420-
import { NxWelcomeComponent } from './nx-welcome.component';
423+
import { NxWelcome } from './nx-welcome';
421424

422425
export const appRoutes: Route[] = [
423426
{
424427
path: '',
425-
component: NxWelcomeComponent,
428+
component: NxWelcome,
426429
pathMatch: 'full',
427430
},
428431
{
429432
path: 'products',
430433
loadComponent: () =>
431-
import('@angular-monorepo/products').then((m) => m.ProductsComponent),
434+
import('@angular-monorepo/products').then((m) => m.Products),
432435
},
433436
];
434437
```
@@ -439,51 +442,51 @@ Serving your app (`npx nx serve angular-store`) and then navigating to `/product
439442

440443
Let's apply the same for our `orders` library.
441444

442-
- import the `OrdersComponent` from `libs/orders` into the `app.routes.ts` and render it via the routing mechanism whenever a user hits the `/orders` route
445+
- import the `Orders` from `libs/orders` into the `app.routes.ts` and render it via the routing mechanism whenever a user hits the `/orders` route
443446

444447
In the end, your `app.routes.ts` should look similar to this:
445448

446449
```ts {% fileName="apps/angular-store/src/app/app.routes.ts" highlightLines=[15,16,17,18,19] %}
447450
import { Route } from '@angular/router';
448-
import { NxWelcomeComponent } from './nx-welcome.component';
451+
import { NxWelcome } from './nx-welcome';
449452

450453
export const appRoutes: Route[] = [
451454
{
452455
path: '',
453-
component: NxWelcomeComponent,
456+
component: NxWelcome,
454457
pathMatch: 'full',
455458
},
456459
{
457460
path: 'products',
458461
loadComponent: () =>
459-
import('@angular-monorepo/products').then((m) => m.ProductsComponent),
462+
import('@angular-monorepo/products').then((m) => m.Products),
460463
},
461464
{
462465
path: 'orders',
463466
loadComponent: () =>
464-
import('@angular-monorepo/orders').then((m) => m.OrdersComponent),
467+
import('@angular-monorepo/orders').then((m) => m.Orders),
465468
},
466469
];
467470
```
468471

469472
Let's also show products in the `inventory` app.
470473

471-
```ts {% fileName="apps/inventory/src/app/app.component.ts" highlightLines=[2,5] %}
474+
```ts {% fileName="apps/inventory/src/app/app.ts" highlightLines=[2,5] %}
472475
import { Component } from '@angular/core';
473-
import { ProductsComponent } from '@angular-monorepo/products';
476+
import { Products } from '@angular-monorepo/products';
474477

475478
@Component({
476-
imports: [ProductsComponent],
479+
imports: [Products],
477480
selector: 'app-root',
478-
templateUrl: './app.component.html',
479-
styleUrl: './app.component.css',
481+
templateUrl: './app.html',
482+
styleUrl: './app.css',
480483
})
481-
export class AppComponent {
484+
export class App {
482485
title = 'inventory';
483486
}
484487
```
485488

486-
```ts {% fileName="apps/inventory/src/app/app.component.html" %}
489+
```ts {% fileName="apps/inventory/src/app/app.html" %}
487490
<lib-products></lib-products>
488491
```
489492

@@ -909,7 +912,7 @@ git commit -a -m "some commit message"
909912

910913
And then make a small change to the `products` library.
911914

912-
```html {% fileName="libs/products/src/lib/product-list/product-list.component.html" %}
915+
```html {% fileName="libs/products/src/lib/product-list/product-list.html" %}
913916
<p>product-list works!</p>
914917
<p>This is a change. 👋</p>
915918
```
@@ -1030,10 +1033,10 @@ If you're ready and want to ship your applications, you can build them using
10301033
```{% command="npx nx run-many -t build" path="angular-monorepo" %}
10311034
NX Generating @nx/angular:component
10321035
1033-
CREATE libs/orders/src/lib/order-list/order-list.component.css
1034-
CREATE libs/orders/src/lib/order-list/order-list.component.html
1035-
CREATE libs/orders/src/lib/order-list/order-list.component.spec.ts
1036-
CREATE libs/orders/src/lib/order-list/order-list.component.ts
1036+
CREATE libs/orders/src/lib/order-list/order-list.css
1037+
CREATE libs/orders/src/lib/order-list/order-list.html
1038+
CREATE libs/orders/src/lib/order-list/order-list.spec.ts
1039+
CREATE libs/orders/src/lib/order-list/order-list.ts
10371040
UPDATE libs/orders/src/index.ts
10381041
❯ nx run-many -t build
10391042
@@ -1174,23 +1177,23 @@ To enforce the rules, Nx ships with a custom ESLint rule. Open the `.eslintrc.ba
11741177
}
11751178
```
11761179

1177-
To test it, go to your `libs/products/src/lib/product-list/product-list.component.ts` file and import the `OrdersComponent` from the `orders` project:
1180+
To test it, go to your `libs/products/src/lib/product-list/product-list.ts` file and import the `Orders` component from the `orders` project:
11781181

1179-
```ts {% fileName="libs/products/src/lib/product-list/product-list.component.ts" highlightLines=[4,5] %}
1182+
```ts {% fileName="libs/products/src/lib/product-list/product-list.ts" highlightLines=[4,5] %}
11801183
import { Component } from '@angular/core';
11811184
import { CommonModule } from '@angular/common';
11821185

11831186
// This import is not allowed 👇
1184-
import { OrdersComponent } from '@angular-monorepo/orders';
1187+
import { Orders } from '@angular-monorepo/orders';
11851188

11861189
@Component({
11871190
selector: 'angular-monorepo-product-list',
11881191
standalone: true,
11891192
imports: [CommonModule],
1190-
templateUrl: './product-list.component.html',
1191-
styleUrls: ['./product-list.component.css'],
1193+
templateUrl: './product-list.html',
1194+
styleUrls: ['./product-list.css'],
11921195
})
1193-
export class ProductsComponent {}
1196+
export class Products {}
11941197
```
11951198

11961199
If you lint your workspace you'll get an error now:
@@ -1200,9 +1203,9 @@ NX Running target lint for 7 projects
12001203
✖ nx run products:lint
12011204
Linting "products"...
12021205
1203-
/Users/isaac/Documents/code/nx-recipes/angular-monorepo/libs/products/src/lib/product-list/product-list.component.ts
1206+
/Users/isaac/Documents/code/nx-recipes/angular-monorepo/libs/products/src/lib/product-list/product-list.ts
12041207
5:1 error A project tagged with "scope:products" can only depend on libs tagged with "scope:products", "scope:shared" @nx/enforce-module-boundaries
1205-
5:10 warning 'OrdersComponent' is defined but never used @typescript-eslint/no-unused-vars
1208+
5:10 warning 'Orders' is defined but never used @typescript-eslint/no-unused-vars
12061209
12071210
✖ 2 problems (1 error, 1 warning)
12081211

nx-dev/tutorial/src/content/tutorial/3-angular-monorepo/2a-smart-monorepo/10-affected/content.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ One of the key features of Nx in a monorepo setting is that you're able to run t
1919

2020
If we were developing locally, you could commit your changes so far and then make a small change to the `products` library.
2121

22-
```html {% fileName="libs/products/src/lib/product-list/product-list.component.html" %}
22+
```html {% fileName="libs/products/src/lib/product-list/product-list.html" %}
2323
<p>product-list works!</p>
2424
<p>This is a change. 👋</p>
2525
```

nx-dev/tutorial/src/content/tutorial/3-angular-monorepo/2a-smart-monorepo/11-module-boundaries/_solution/libs/products/src/lib/products.tsx

Lines changed: 0 additions & 15 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Component } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
4+
// This import is not allowed 👇
5+
import { Orders } from '@angular-monorepo/orders';
6+
7+
@Component({
8+
selector: 'lib-products',
9+
imports: [CommonModule],
10+
templateUrl: './products.html',
11+
styleUrl: './products.css',
12+
})
13+
export class Products {}

nx-dev/tutorial/src/content/tutorial/3-angular-monorepo/2a-smart-monorepo/11-module-boundaries/content.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ To enforce the rules, Nx ships with a custom ESLint rule. Open the `eslint.confi
5353

5454
```
5555

56-
To test it, go to your `libs/products/src/lib/products.tsx` file and import the `Orders` component from the `orders` project:
56+
To test it, go to your `libs/products/src/lib/products/products.ts` file and import the `Orders` component from the `orders` project:
5757

58-
```solution:/libs/products/src/lib/products.tsx title="/libs/products/src/lib/products.tsx" {3-4}
58+
```solution:/libs/products/src/lib/products/products.ts title="/libs/products/src/lib/products/products.ts" {4-5}
5959

6060
```
6161

@@ -70,9 +70,9 @@ npx nx run-many -t lint
7070
✖ nx run products:lint
7171
Linting "products"...
7272
73-
/Users/isaac/Documents/code/nx-recipes/angular-monorepo/libs/products/src/lib/products.tsx
74-
4:1 error A project tagged with "scope:products" can only depend on libs tagged with "scope:products", "scope:shared" @nx/enforce-module-boundaries
75-
4:10 warning 'Orders' is defined but never used @typescript-eslint/no-unused-vars
73+
/Users/isaac/Documents/code/nx-recipes/angular-monorepo/libs/products/src/lib/products/products.ts
74+
5:1 error A project tagged with "scope:products" can only depend on libs tagged with "scope:products", "scope:shared" @nx/enforce-module-boundaries
75+
5:10 warning 'Orders' is defined but never used @typescript-eslint/no-unused-vars
7676
7777
✖ 2 problems (1 error, 1 warning)
7878

nx-dev/tutorial/src/content/tutorial/3-angular-monorepo/2a-smart-monorepo/2-use-preset/_solution/angular-monorepo/apps/angular-store/project.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
"tags": [],
88
"targets": {
99
"build": {
10-
"executor": "@angular-devkit/build-angular:application",
10+
"executor": "@angular/build:application",
1111
"outputs": ["{options.outputPath}"],
1212
"options": {
1313
"outputPath": "dist/apps/angular-store",
14-
"index": "apps/angular-store/src/index.html",
1514
"browser": "apps/angular-store/src/main.ts",
1615
"polyfills": ["zone.js"],
1716
"tsConfig": "apps/angular-store/tsconfig.app.json",
@@ -21,8 +20,7 @@
2120
"input": "apps/angular-store/public"
2221
}
2322
],
24-
"styles": ["apps/angular-store/src/styles.css"],
25-
"scripts": []
23+
"styles": ["apps/angular-store/src/styles.css"]
2624
},
2725
"configurations": {
2826
"production": {
@@ -49,7 +47,7 @@
4947
"defaultConfiguration": "production"
5048
},
5149
"serve": {
52-
"executor": "@angular-devkit/build-angular:dev-server",
50+
"executor": "@angular/build:dev-server",
5351
"configurations": {
5452
"production": {
5553
"buildTarget": "angular-store:build:production"
@@ -61,7 +59,7 @@
6159
"defaultConfiguration": "development"
6260
},
6361
"extract-i18n": {
64-
"executor": "@angular-devkit/build-angular:extract-i18n",
62+
"executor": "@angular/build:extract-i18n",
6563
"options": {
6664
"buildTarget": "angular-store:build"
6765
}

0 commit comments

Comments
 (0)