-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Answer:16 dependency injection #1525
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,13 @@ | ||
| import { TableComponent } from '@angular-challenges/shared/ui'; | ||
| import { AsyncPipe } from '@angular/common'; | ||
| import { ChangeDetectionStrategy, Component, Directive } from '@angular/core'; | ||
| import { | ||
| ChangeDetectionStrategy, | ||
| Component, | ||
| Directive, | ||
| effect, | ||
| inject, | ||
| input, | ||
| } from '@angular/core'; | ||
| import { CurrencyPipe } from './currency.pipe'; | ||
| import { CurrencyService } from './currency.service'; | ||
| import { Product, products } from './product.model'; | ||
|
|
@@ -22,9 +29,27 @@ export class ProductDirective { | |
| } | ||
| } | ||
|
|
||
| @Component({ | ||
| imports: [TableComponent, CurrencyPipe, AsyncPipe, ProductDirective], | ||
| @Directive({ | ||
| selector: 'tr[currencyCode]', | ||
| providers: [CurrencyService], | ||
| }) | ||
| export class ProductRowDirective { | ||
| #currencyService = inject(CurrencyService); | ||
| currencyCode = input.required<string>(); | ||
|
|
||
| #syncCodeEffectRef = effect(() => { | ||
| this.#currencyService.patchState({ code: this.currencyCode() }); | ||
| }); | ||
|
Comment on lines
+40
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: git ls-files apps/angular/16-master-dependency-injection/src/app/app.component.ts && printf '\n---\n' && cat -n apps/angular/16-master-dependency-injection/src/app/app.component.tsRepository: tomalaforge/angular-challenges Length of output: 2772 🏁 Script executed: rg -n "no-unused-private-class-members|EffectRef|effect\(" apps/angular/16-master-dependency-injection/src/app -SRepository: tomalaforge/angular-challenges Length of output: 278 Drop the unused 🧰 Tools🪛 ESLint[error] 40-40: ' (no-unused-private-class-members) 🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||
| } | ||
|
|
||
| @Component({ | ||
| imports: [ | ||
| TableComponent, | ||
| CurrencyPipe, | ||
| AsyncPipe, | ||
| ProductDirective, | ||
| ProductRowDirective, | ||
| ], | ||
| selector: 'app-root', | ||
| template: ` | ||
| <table [items]="products"> | ||
|
|
@@ -38,7 +63,7 @@ export class ProductDirective { | |
| </tr> | ||
| </ng-template> | ||
| <ng-template #body product let-product> | ||
| <tr> | ||
| <tr [currencyCode]="product.currencyCode"> | ||
| <td>{{ product.name }}</td> | ||
| <td>{{ product.priceA | currency | async }}</td> | ||
| <td>{{ product.priceB | currency | async }}</td> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: tomalaforge/angular-challenges
Length of output: 11889
🏁 Script executed:
Repository: tomalaforge/angular-challenges
Length of output: 1098
Prefix the row directive selector to match the lint rule.
@angular-eslint/directive-selectorhere requires anapp-prefixed attribute selector, sotr[currencyCode]will fail lint. Rename it to something liketr[appCurrencyCode]and update the template binding at line 66, or add a local disable if this exact selector is intentional.🧰 Tools
🪛 ESLint
[error] 33-33: The selector should start with one of these prefixes: "app"
(
@angular-eslint/directive-selector)🤖 Prompt for AI Agents
Source: Linters/SAST tools