Code Monkey home page Code Monkey logo

di's Introduction

Di

Angular Challenges #16 Dependency Injection

Directions

To successfully complete this challenge, you will need to have a good understanding of how Dependency Injection works inside Angular.

The goal is to provide the CurrencyService at the row level, so that each row displays the correct currency. Currently, the CurrencyService is only provided at the table level, which results in an error as the same currency is displayed for each row, despite each product having a different currency.

One way to achieve this is by adding a second argument to the pipe, but this is not allowed.

Statement

Your task is to display the correct currency for each row.

Constraints:

You cannot modify the pipe. You cannot wrap the row inside a component, as this will break the layout.

Thoughts

  • If you wrap each row inside another component, then you can initialize a store for each wrapper component.
  • I modified the pipe just to see what it would take to achieve the result.
  • I passed currencyCode to the pipe. I was able to display the currencyCode but displaying the symbol doesn't seem possible without a dictionary / lookup object.
  • I tried to use patchState inside the transform pipe but you get Error: NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: '1000 US$'. Current value: '1000 โ‚ฌ'.
  • Also, "Writing to signals is not allowed in a computed or an effect by default. Use allowSignalWrites in the CreateEffectOptions to enable this inside effects."
  • The currency object is already exported so I imported it and used the find method to get the symbol in the html.

Useful Resources

  • Stack Overflow - how do I call angular pipe with multiple arguments
  • Stack Overflow - inheritance and dependency injection
  • Stack Overflow - angular extending services and passing parameters
  • NgJournal - component store meets facade pattern
  • Angular University - angular redux ngrx rxjs
  • Stack Overflow - how can i call a service from a directive in angular 2
  • Stack Overflow - how to inject a service into a directive in angular 13
  • Stack Overflow - inject a service into a directive
  • Dev.to - Superpowers with Directives and Dependency Injection Series' Articles
  • Angular Snippets - stateful directive with output
  • Stack Overflow - how to pass values to directive in angular
  • YouTube - Custom Directive in Angular - Attribute Directive | Structural Directive | Component Directive

di's People

Contributors

jdegand avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.