diff --git a/aio/content/examples/attribute-directives/src/app/highlight.directive.1.ts b/aio/content/examples/attribute-directives/src/app/highlight.directive.1.ts index 1ce9949ec0d..77d1998737b 100644 --- a/aio/content/examples/attribute-directives/src/app/highlight.directive.1.ts +++ b/aio/content/examples/attribute-directives/src/app/highlight.directive.1.ts @@ -6,7 +6,7 @@ import { Directive, ElementRef } from '@angular/core'; selector: '[appHighlight]' }) export class HighlightDirective { - constructor(el: ElementRef) { - el.nativeElement.style.backgroundColor = 'yellow'; + constructor(private el: ElementRef) { + this.el.nativeElement.style.backgroundColor = 'yellow'; } } diff --git a/aio/content/examples/attribute-directives/src/app/highlight.directive.3.ts b/aio/content/examples/attribute-directives/src/app/highlight.directive.3.ts index 00380664fe5..17d64b91387 100644 --- a/aio/content/examples/attribute-directives/src/app/highlight.directive.3.ts +++ b/aio/content/examples/attribute-directives/src/app/highlight.directive.3.ts @@ -14,9 +14,11 @@ export class HighlightDirective { @Input() appHighlight = ''; // #enddocregion input + // #docregion mouse-enter @HostListener('mouseenter') onMouseEnter() { this.highlight(this.appHighlight || 'red'); } + // #enddocregion mouse-enter @HostListener('mouseleave') onMouseLeave() { this.highlight(''); diff --git a/aio/content/examples/attribute-directives/src/app/highlight.directive.ts b/aio/content/examples/attribute-directives/src/app/highlight.directive.ts index 76bbfd1771a..2a37b5bbfdc 100644 --- a/aio/content/examples/attribute-directives/src/app/highlight.directive.ts +++ b/aio/content/examples/attribute-directives/src/app/highlight.directive.ts @@ -12,11 +12,11 @@ export class HighlightDirective { @Input() defaultColor = ''; // #enddocregion defaultColor - @Input('appHighlight') highlightColor = ''; + @Input() appHighlight = ''; // #docregion mouse-enter @HostListener('mouseenter') onMouseEnter() { - this.highlight(this.highlightColor || this.defaultColor || 'red'); + this.highlight(this.appHighlight || this.defaultColor || 'red'); } // #enddocregion mouse-enter diff --git a/aio/content/guide/attribute-directives.md b/aio/content/guide/attribute-directives.md index a126e5e72ce..e3b94ad2e8a 100644 --- a/aio/content/guide/attribute-directives.md +++ b/aio/content/guide/attribute-directives.md @@ -120,6 +120,10 @@ This section guides you through adding radio buttons to bind your color choice t +1. In `highlight.directive.ts`, revise `onMouseEnter` method so that it first tries to highlight with `appHighlight` and falls back to `red` if `appHighlight` is `undefined`. + + + 1. Serve your application to verify that the user can choose the color with the radio buttons.