Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(docs-infra): improve the content of attribute directives #44628

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,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';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,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('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,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

Expand Down
6 changes: 5 additions & 1 deletion aio/content/guide/attribute-directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ This section guides you through adding radio buttons to bind your color choice t

<code-example path="attribute-directives/src/app/app.component.ts" header="src/app/app.component.ts (class)" region="class"></code-example>

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`.

<code-example path="attribute-directives/src/app/highlight.directive.3.ts" header="src/app/highlight.directive.ts (mouse-enter)" region="mouse-enter"></code-example>

1. Serve your application to verify that the user can choose the color with the radio buttons.

<div class="lightbox">
Expand All @@ -136,7 +140,7 @@ This section guides you through configuring your application so the developer ca

<code-example path="attribute-directives/src/app/highlight.directive.ts" header="src/app/highlight.directive.ts (defaultColor)" region="defaultColor"></code-example>

1. Revise the directive's `onMouseEnter` so that it first tries to highlight with the `highlightColor`, then with the `defaultColor`, and falls back to `red` if both properties are `undefined`.
1. Revise the directive's `onMouseEnter` so that it first tries to highlight with the `appHighlight`, then with the `defaultColor`, and falls back to `red` if both properties are `undefined`.

<code-example path="attribute-directives/src/app/highlight.directive.ts" header="src/app/highlight.directive.ts (mouse-enter)" region="mouse-enter"></code-example>

Expand Down