docs: make the `spy-directive` docregion (in `lifecycle-hooks` example) easier to follow (#40208)
Previously, the docregion code referenced a `nextId` variable that was not shown in the code, which was confusing for the reader. This commit makes the declaration of the `nextId` variable part of the docregion, so it is clear to the reader where it comes from and how it is initialized. This commit also removes the `logIt()` helper method, which didn't seem to add value and calls `logger.log()` directly instead. PR Close #40208
This commit is contained in:
parent
251b27701f
commit
e28d460307
|
@ -3,9 +3,9 @@ import { Directive, OnInit, OnDestroy } from '@angular/core';
|
|||
|
||||
import { LoggerService } from './logger.service';
|
||||
|
||||
// #docregion spy-directive
|
||||
let nextId = 1;
|
||||
|
||||
// #docregion spy-directive
|
||||
// Spy on any element to which it is applied.
|
||||
// Usage: <div appSpy>...</div>
|
||||
@Directive({selector: '[appSpy]'})
|
||||
|
@ -13,12 +13,12 @@ export class SpyDirective implements OnInit, OnDestroy {
|
|||
|
||||
constructor(private logger: LoggerService) { }
|
||||
|
||||
ngOnInit() { this.logIt(`onInit`); }
|
||||
ngOnInit() {
|
||||
this.logger.log(`Spy #${nextId++} onInit`);
|
||||
}
|
||||
|
||||
ngOnDestroy() { this.logIt(`onDestroy`); }
|
||||
|
||||
private logIt(msg: string) {
|
||||
this.logger.log(`Spy #${nextId++} ${msg}`);
|
||||
ngOnDestroy() {
|
||||
this.logger.log(`Spy #${nextId++} onDestroy`);
|
||||
}
|
||||
}
|
||||
// #enddocregion spy-directive
|
||||
|
|
Loading…
Reference in New Issue