docs: update testing doc example style for HostListener (#26372)
HostListener is preferred over host metadata by official style guide PR Close #26372
This commit is contained in:
parent
f1fb62d1e5
commit
cfb41452ce
|
@ -1,4 +1,4 @@
|
||||||
import { Directive, Input } from '@angular/core';
|
import { Directive, Input, HostListener } from '@angular/core';
|
||||||
|
|
||||||
// export for convenience.
|
// export for convenience.
|
||||||
export { RouterLink} from '@angular/router';
|
export { RouterLink} from '@angular/router';
|
||||||
|
@ -6,13 +6,13 @@ export { RouterLink} from '@angular/router';
|
||||||
/* tslint:disable:directive-class-suffix */
|
/* tslint:disable:directive-class-suffix */
|
||||||
// #docregion router-link
|
// #docregion router-link
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[routerLink]',
|
selector: '[routerLink]'
|
||||||
host: { '(click)': 'onClick()' }
|
|
||||||
})
|
})
|
||||||
export class RouterLinkDirectiveStub {
|
export class RouterLinkDirectiveStub {
|
||||||
@Input('routerLink') linkParams: any;
|
@Input('routerLink') linkParams: any;
|
||||||
navigatedTo: any = null;
|
navigatedTo: any = null;
|
||||||
|
|
||||||
|
@HostListener('click')
|
||||||
onClick() {
|
onClick() {
|
||||||
this.navigatedTo = this.linkParams;
|
this.navigatedTo = this.linkParams;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2205,7 +2205,7 @@ seen in the `AppComponent` template.
|
||||||
|
|
||||||
The URL bound to the `[routerLink]` attribute flows in to the directive's `linkParams` property.
|
The URL bound to the `[routerLink]` attribute flows in to the directive's `linkParams` property.
|
||||||
|
|
||||||
The `host` metadata property wires the click event of the host element
|
The `HostListener` wires the click event of the host element
|
||||||
(the `<a>` anchor elements in `AppComponent`) to the stub directive's `onClick` method.
|
(the `<a>` anchor elements in `AppComponent`) to the stub directive's `onClick` method.
|
||||||
|
|
||||||
Clicking the anchor should trigger the `onClick()` method,
|
Clicking the anchor should trigger the `onClick()` method,
|
||||||
|
|
Loading…
Reference in New Issue