Coder Social home page Coder Social logo

pdecembre / angular4sharedservice Goto Github PK

View Code? Open in Web Editor NEW

This project forked from iainplimmer/angular4sharedservice

0.0 2.0 0.0 15 KB

Example of sharing a service in Angular 4 with RXJS through two components.

TypeScript 81.60% JavaScript 13.67% CSS 1.28% HTML 3.45%

angular4sharedservice's Introduction

Synclist

Synopsis

Project created to explore sharing services in an Angular4 application using RXJS. RXJS is only being used in the place of a promise. That will need more exploration as it's a massive surface area and to be honest I get how it works but not how i can use it effectively. One for another day.

The Objective

  1. Create a service that can be shared in multiple components so that we only call it once.
  2. Create two components that consume the service.
  3. Changing a value in one of the components reflects in both.

The Solution

We create a service called TaskService, initialise it in the main app.component then inject the service into the other components, referring to the value that has been initilised in the app.component.

It's quite simple, but took a little while to get my head around how it could be achieved.

Using NgModel we can then reflect the changes back into the service and across other shared components.

(This project was generated with Angular CLI version 1.0.0.)

Development server

Run ng serve for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.

angular4sharedservice's People

Contributors

angular-cli avatar

Watchers

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