Skip to content

Commit a99f30c

Browse files
authored
use standalone for components
1 parent 244906c commit a99f30c

37 files changed

+91
-383
lines changed

apps/example-app/src/app/app.module.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ function reducerItems() {
2828
}
2929

3030
@NgModule({
31-
declarations: [
32-
AppComponent,
31+
declarations: [AppComponent],
32+
imports: [
3333
SingleComponent,
3434
NestedButtonComponent,
3535
NestedValueComponent,
@@ -43,8 +43,6 @@ function reducerItems() {
4343
RootComponent,
4444
DetailComponent,
4545
HiddenDetailComponent,
46-
],
47-
imports: [
4846
BrowserModule,
4947
ReactiveFormsModule,
5048
BrowserAnimationsModule,

apps/example-app/src/app/examples/00-single-component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Component } from '@angular/core';
22

33
@Component({
44
selector: 'app-fixture',
5+
standalone: true,
56
template: `
67
<button (click)="value = value - 1">Decrement</button>
78
<span data-testid="value">{{ value }}</span>

apps/example-app/src/app/examples/01-nested-component.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { render, screen } from '@testing-library/angular';
22
import userEvent from '@testing-library/user-event';
33

4-
import { NestedButtonComponent, NestedValueComponent, NestedContainerComponent } from './01-nested-component';
4+
import { NestedContainerComponent } from './01-nested-component';
55

66
test('renders the current value and can increment and decrement', async () => {
77
const user = userEvent.setup();
8-
await render(NestedContainerComponent, {
9-
declarations: [NestedButtonComponent, NestedValueComponent],
10-
});
8+
await render(NestedContainerComponent);
119

1210
const incrementControl = screen.getByRole('button', { name: /increment/i });
1311
const decrementControl = screen.getByRole('button', { name: /decrement/i });

apps/example-app/src/app/examples/01-nested-component.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Component, Input, Output, EventEmitter } from '@angular/core';
22

33
@Component({
4+
standalone: true,
45
selector: 'app-button',
56
template: ' <button (click)="raise.emit()">{{ name }}</button> ',
67
})
@@ -10,6 +11,7 @@ export class NestedButtonComponent {
1011
}
1112

1213
@Component({
14+
standalone: true,
1315
selector: 'app-value',
1416
template: ' <span data-testid="value">{{ value }}</span> ',
1517
})
@@ -18,12 +20,14 @@ export class NestedValueComponent {
1820
}
1921

2022
@Component({
23+
standalone: true,
2124
selector: 'app-fixture',
2225
template: `
23-
<app-button (raise)="value = value - 1" name="Decrement"></app-button>
24-
<app-value [value]="value"></app-value>
25-
<app-button (raise)="value = value + 1" name="Increment"></app-button>
26+
<app-button (raise)="value = value - 1" name="Decrement" />
27+
<app-value [value]="value" />
28+
<app-button (raise)="value = value + 1" name="Increment" />
2629
`,
30+
imports: [NestedButtonComponent, NestedValueComponent],
2731
})
2832
export class NestedContainerComponent {
2933
value = 0;

apps/example-app/src/app/examples/02-input-output.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ test('is possible to set input and listen for output with the template syntax',
3838
const user = userEvent.setup();
3939
const sendSpy = jest.fn();
4040

41-
await render('<app-fixture [value]="47" (sendValue)="sendValue($event)" (clicked)="clicked()"></app-fixture>', {
42-
declarations: [InputOutputComponent],
41+
await render('<app-fixture [value]="47" (sendValue)="sendValue($event)" />', {
42+
imports: [InputOutputComponent],
4343
componentProperties: {
4444
sendValue: sendSpy,
4545
},

apps/example-app/src/app/examples/02-input-output.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Component, EventEmitter, Input, Output } from '@angular/core';
22

33
@Component({
4+
standalone: true,
45
selector: 'app-fixture',
56
template: `
67
<button (click)="value = value - 1">Decrement</button>

apps/example-app/src/app/examples/03-forms.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import { NgForOf, NgIf } from '@angular/common';
12
import { Component } from '@angular/core';
2-
import { FormBuilder, Validators } from '@angular/forms';
3+
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
34

45
@Component({
6+
standalone: true,
57
selector: 'app-fixture',
8+
imports: [ReactiveFormsModule, NgForOf, NgIf],
69
template: `
710
<form [formGroup]="form" name="form">
811
<div>

apps/example-app/src/app/examples/04-forms-with-material.spec.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import { render, screen } from '@testing-library/angular';
22
import userEvent from '@testing-library/user-event';
33

4-
import { MaterialModule } from '../material.module';
54
import { MaterialFormsComponent } from './04-forms-with-material';
65

76
test('is possible to fill in a form and verify error messages (with the help of jest-dom https://testing-library.com/docs/ecosystem-jest-dom)', async () => {
87
const user = userEvent.setup();
98

10-
const { fixture } = await render(MaterialFormsComponent, {
11-
imports: [MaterialModule],
12-
});
9+
const { fixture } = await render(MaterialFormsComponent);
1310

1411
const nameControl = screen.getByLabelText(/name/i);
1512
const scoreControl = screen.getByRole('spinbutton', { name: /score/i });
@@ -69,9 +66,7 @@ test('is possible to fill in a form and verify error messages (with the help of
6966
test('set and show pre-set form values', async () => {
7067
const user = userEvent.setup();
7168

72-
const { fixture, detectChanges } = await render(MaterialFormsComponent, {
73-
imports: [MaterialModule],
74-
});
69+
const { fixture, detectChanges } = await render(MaterialFormsComponent);
7570

7671
fixture.componentInstance.form.setValue({
7772
name: 'Max',

apps/example-app/src/app/examples/04-forms-with-material.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { Component } from '@angular/core';
2-
import { FormBuilder, Validators } from '@angular/forms';
2+
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
3+
import { MaterialModule } from '../material.module';
4+
import { NgForOf, NgIf } from '@angular/common';
35

46
@Component({
7+
standalone: true,
8+
imports: [MaterialModule, ReactiveFormsModule, NgForOf, NgIf],
59
selector: 'app-fixture',
610
template: `
711
<form [formGroup]="form" name="form">

apps/example-app/src/app/examples/05-component-provider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class CounterService {
2020
}
2121

2222
@Component({
23+
standalone: true,
2324
selector: 'app-fixture',
2425
template: `
2526
<button (click)="counter.decrement()">Decrement</button>

0 commit comments

Comments
 (0)