Skip to content

Commit 658fb0a

Browse files
devversiondylhunn
authored andcommitted
refactor(core): improve API documentation for output (#55053)
This improves the API documentatino for `output` in angular.dev, similar to how we improved the API for `input`. Angular.dev can now show these documentation entries more readable if annotated explicitly as initializer API. Note: output API is short enough that we want to include the types in the code snippet previews. PR Close #55053
1 parent f8aa778 commit 658fb0a

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

packages/core/src/authoring/output/output.ts

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,47 @@ export interface OutputOptions {
2020
}
2121

2222
/**
23-
* The `output` function allows declaration of outputs in directives and
24-
* components.
23+
* The `output` function allows declaration of Angular outputs in
24+
* directives and components.
2525
*
26-
* Initializes an output that can emit values to consumers of your
27-
* directive/component.
26+
* You can use outputs to emit values to parent directives and component.
27+
* Parents can subscribe to changes via:
28+
*
29+
* - template event bindings. For example, `(myOutput)="doSomething($event)"`
30+
* - programmatic subscription by using `OutputRef#subscribe`.
2831
*
2932
* @usageNotes
30-
* Initialize an output in your directive by declaring a
31-
* class field and initializing it with the `output()` function.
33+
*
34+
* To use `output()`, import the function from `@angular/core`.
35+
*
36+
* ```
37+
* import {output} from '@angular/core`;
38+
* ```
39+
*
40+
* Inside your component, introduce a new class member and initialize
41+
* it with a call to `output`.
3242
*
3343
* ```ts
34-
* @Directive({..})
44+
* @Directive({
45+
* ...
46+
* })
3547
* export class MyDir {
36-
* nameChange = output<string>(); // OutputEmitterRef<string>
37-
* onClick = output(); // OutputEmitterRef<void>
48+
* nameChange = output<string>(); // OutputEmitterRef<string>
49+
* onClick = output(); // OutputEmitterRef<void>
50+
* }
51+
* ```
52+
*
53+
* You can emit values to consumers of your directive, by using
54+
* the `emit` method from `OutputEmitterRef`.
55+
*
56+
* ```ts
57+
* updateName(newName: string): void {
58+
* this.nameChange.emit(newName);
3859
* }
3960
* ```
4061
*
4162
* @developerPreview
63+
* @initializerApiFunction {"showTypesInSignaturePreview": true}
4264
*/
4365
export function output<T = void>(opts?: OutputOptions): OutputEmitterRef<T> {
4466
ngDevMode && assertInInjectionContext(output);

0 commit comments

Comments
 (0)