Skip to content

Commit a568742

Browse files
committed
feat(hero): added highlight directive
1 parent b7fb497 commit a568742

4 files changed

Lines changed: 15 additions & 2 deletions

File tree

app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<h1>{{title}}</h1>
1+
<h1 tohHighlight>{{title}}</h1>
22
<toh-nav></toh-nav>
33
<router-outlet></router-outlet>

app/app.module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { InMemoryDataService } from './shared/in-memory-data.service';
1515
import { AppComponent } from './app.component';
1616
import { HeroTopComponent } from './heroes/hero-top/hero-top.component';
1717

18+
import { HighlightDirective } from "./shared/highlight.directive";
19+
1820
import './shared/rxjs-extensions';
1921

2022
@NgModule({
@@ -29,7 +31,8 @@ import './shared/rxjs-extensions';
2931
],
3032
declarations: [
3133
AppComponent,
32-
HeroTopComponent
34+
HeroTopComponent,
35+
HighlightDirective
3336
],
3437
providers: [
3538
{ provide: APP_CONFIG, useValue: AppConfig }

app/heroes/hero-list/hero-list.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ <h2>My Heroes</h2>
1818
<h2>
1919
{{selectedHero.name | uppercase}} is my hero
2020
</h2>
21+
<p tohHighlight>Test</p>
2122
<button (click)="gotoDetail()">View Details</button>
2223
</div>

app/shared/highlight.directive.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Directive, ElementRef, Input } from '@angular/core';
2+
3+
@Directive({ selector: '[tohHighlight]' })
4+
5+
export class HighlightDirective {
6+
constructor(el: ElementRef) {
7+
el.nativeElement.style.backgroundColor = 'yellow';
8+
}
9+
}

0 commit comments

Comments
 (0)