From e28d460307600c15fc9c0f98c7ad26660b76bf77 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Mon, 21 Dec 2020 17:23:59 +0200 Subject: [PATCH] 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 --- .../lifecycle-hooks/src/app/spy.directive.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/aio/content/examples/lifecycle-hooks/src/app/spy.directive.ts b/aio/content/examples/lifecycle-hooks/src/app/spy.directive.ts index c14f4e6455..16f9440073 100644 --- a/aio/content/examples/lifecycle-hooks/src/app/spy.directive.ts +++ b/aio/content/examples/lifecycle-hooks/src/app/spy.directive.ts @@ -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:
...
@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