Giter Club home page Giter Club logo

angular-and-states's Introduction

My Skills My Skills Angular And States My Skills My Skills

Communication between components in Angular is really important when building an Angular App, we usually communicate parent-children components adding Input/Output events on. However, when our App starts to grow either with routing or in number of components, we opt to go for services with RxJs to do this implementation.

These services are based on a Behavior Subject property and subscription (AsObservable) in order to get the data asynchronoulsy. But if the reaction/services increase in several components this technique sometimes is quite difficult to maintain on a long-term basis.

That's why AppService has been built for, to avoid multiple injections of different services in any single component, it is acting as a bridge combining multiple behavior Subjects placed in different services.



๐Ÿ’ป State in Services ๐Ÿ’ป

As I mentioned above, single services are needed to save state of each section, as you can see in the snapshot below Behavior Subject is setting the data in the Behavior Subject for later being called AsObservable at any level of the App.

service simple

๐Ÿ’ป Bridge Service ๐Ÿ’ป

Centralizing all the Behavior Subjects will provide all states in the App just calling one service, we will provide a single entry creating AppService to expose customerAndBalance$ in a single object, which is very straight forward to handle when retrieving the data in any component.

service

๐Ÿ’ป Combining Observables ๐Ÿ’ป

CombineLatest RxJs operator used to combine each service data in a single object which is going to be rendered in customer-message component. As returns an Observable async pipe has accompanied the data in the template to identify changes in the subscription.

combineLatest

๐Ÿ’ป Nesting Conditions in the template ๐Ÿ’ป

NgIf else, ng-container, ng-template are structural directives applied in customer-message component to render part of the template depending which variable is providing the data to let the user know if any action is required. With this technique we can play with for different scenarios in order to show messages in the DOM.

render

How to clone

  • git clone https://github.com/JoseMMorales/Angular-And-States.git
  • cd Angular-And-States
  • code . if using VSCode

Technology

angular: "14.2.0"
rxjs: "7.5.0"
typescript: "4.7"
bootstrap: "5.2"
jasmine: "4.3"
Karma: "5.1"

Author

JoseMMorales

angular-and-states's People

Contributors

josemmorales avatar

Stargazers

 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.