Skip to content

Commit 9deaa67

Browse files
docs: replace EventEmitter with output and self-closing tags in templates (angular#60910)
Replaced all instances of EventEmitter with the new output() utility. Updated templates to use self-closing tags for cleaner markup. PR Close angular#60910
1 parent cebb9d2 commit 9deaa67

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

packages/core/src/metadata/directives.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ export interface ComponentDecorator {
423423
*
424424
* ### Setting component outputs
425425
*
426-
* The following example shows two event emitters that emit on an interval. One
426+
* The following example shows two output function that emit on an interval. One
427427
* emits an output every second, while the other emits every five seconds.
428428
*
429429
* {@example core/ts/metadata/directives.ts region='component-output-interval'}

packages/examples/core/ts/metadata/directives.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88
/* tslint:disable:no-console */
9-
import {Component, Directive, EventEmitter, NgModule} from '@angular/core';
9+
import {Component, Directive, output} from '@angular/core';
1010

1111
// #docregion component-input
1212
@Component({
1313
selector: 'app-bank-account',
1414
inputs: ['bankName', 'id: account-id'],
1515
template: ` Bank Name: {{ bankName }} Account Id: {{ id }} `,
16-
standalone: false,
1716
})
1817
export class BankAccountComponent {
1918
bankName: string | null = null;
@@ -25,35 +24,32 @@ export class BankAccountComponent {
2524

2625
@Component({
2726
selector: 'app-my-input',
28-
template: ` <app-bank-account bankName="RBC" account-id="4747"> </app-bank-account> `,
29-
standalone: false,
27+
template: ` <app-bank-account bankName="RBC" account-id="4747" /> `,
28+
imports: [BankAccountComponent],
3029
})
3130
export class MyInputComponent {}
3231
// #enddocregion component-input
3332

3433
// #docregion component-output-interval
3534
@Directive({
3635
selector: 'app-interval-dir',
37-
outputs: ['everySecond', 'fiveSecs: everyFiveSeconds'],
38-
standalone: false,
3936
})
4037
export class IntervalDirComponent {
41-
everySecond = new EventEmitter<string>();
42-
fiveSecs = new EventEmitter<string>();
38+
everySecond = output<string>();
39+
everyFiveSeconds = output<string>();
4340

4441
constructor() {
4542
setInterval(() => this.everySecond.emit('event'), 1000);
46-
setInterval(() => this.fiveSecs.emit('event'), 5000);
43+
setInterval(() => this.everyFiveSeconds.emit('event'), 5000);
4744
}
4845
}
4946

5047
@Component({
5148
selector: 'app-my-output',
5249
template: `
53-
<app-interval-dir (everySecond)="onEverySecond()" (everyFiveSeconds)="onEveryFiveSeconds()">
54-
</app-interval-dir>
50+
<app-interval-dir (everySecond)="onEverySecond()" (everyFiveSeconds)="onEveryFiveSeconds()" />
5551
`,
56-
standalone: false,
52+
imports: [IntervalDirComponent],
5753
})
5854
export class MyOutputComponent {
5955
onEverySecond() {
@@ -64,8 +60,3 @@ export class MyOutputComponent {
6460
}
6561
}
6662
// #enddocregion component-output-interval
67-
68-
@NgModule({
69-
declarations: [BankAccountComponent, MyInputComponent, IntervalDirComponent, MyOutputComponent],
70-
})
71-
export class AppModule {}

0 commit comments

Comments
 (0)