<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Attila Müller on Medium]]></title>
        <description><![CDATA[Stories by Attila Müller on Medium]]></description>
        <link>https://medium.com/@muller.attila.aron?source=rss-20353e50dfd8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*uVpv-Ei66uUovkCc1Q2jTw.jpeg</url>
            <title>Stories by Attila Müller on Medium</title>
            <link>https://medium.com/@muller.attila.aron?source=rss-20353e50dfd8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 01:25:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@muller.attila.aron/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Let’s build a small application using Observable Data Services and Angular!]]></title>
            <link>https://medium.com/betsson-group/lets-build-a-small-application-using-observable-data-services-and-angular-8c253068ed18?source=rss-20353e50dfd8------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c253068ed18</guid>
            <category><![CDATA[observables]]></category>
            <category><![CDATA[rxjs]]></category>
            <category><![CDATA[material-design]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Attila Müller]]></dc:creator>
            <pubDate>Mon, 18 Nov 2019 07:01:01 GMT</pubDate>
            <atom:updated>2019-11-18T07:01:01.436Z</atom:updated>
            <content:encoded><![CDATA[<p>Building even small applications can be challenging if they involve asynchronous data. Data flow in particular can be difficult to solve. In this example, I would like to show how easy it is to fetch data from an API and present it to the user using <strong>Angular</strong>🚀 and <strong>Observables</strong>⚡️.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*371hPR05PWSIkKjbok4V2g.png" /><figcaption><a href="https://football-standings-7f1cc.firebaseapp.com/">Check the deployed application here</a></figcaption></figure><p>We are going to get the standings of top football leagues from <a href="https://www.football-data.org/"><strong>football-data.org</strong></a>⚽️ and we will use <strong>RxJs Subjects</strong>🔥 to feed information through <strong>Observable Data Services</strong> to components.</p><p>It is important to have fancy modern-looking components so we import <a href="https://material.angular.io/"><strong>Angular Material</strong></a> into the project (and what is more beautiful than a stylish gradient going from purple to blue in the background right? 🦄). <a href="https://football-standings-7f1cc.firebaseapp.com/">You can check the deployed application here</a> and the <a href="https://github.com/AttilaMuller/football-standings">public git repository here</a>.</p><p>Let’s get started with generating an Angular project. If you do not have Angular CLI installed run:</p><pre>npm install -g <a href="http://twitter.com/angular/cli">@angular/cli</a></pre><p>then create a new project:</p><pre>ng new football-standings</pre><p>and finally add Material:</p><pre>ng add <a href="http://twitter.com/angular/material">@angular/material</a></pre><p>At this point we need three folders for our components, models, and services so structure looks like this:</p><pre>|-src<br>|--app<br>|—--<strong>components</strong><br>|—--<strong>models</strong><br>|---<strong>services</strong></pre><p>I am going to start with generating a service which will be called <strong>StandingService </strong>with the following command<strong>:</strong></p><pre>ng g s standing</pre><p>As the title suggests we are going to use an Observable Data Service which means that an RxJs Subject will be used to emit values that will be received by the component. A <a href="https://rxjs-dev.firebaseapp.com/guide/subject">Subject</a> is a special type of <a href="https://rxjs-dev.firebaseapp.com/guide/observable">Observable </a>that can be used to emit values and can be also be subscribed to. This means that we can feed data into it and emit those values to any observers that are subscribed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/820894cc144cae6e84824a00d91aee00/href">https://medium.com/media/820894cc144cae6e84824a00d91aee00/href</a></iframe><p>There is a reason I’m using a <a href="https://www.learnrxjs.io/subjects/behaviorsubject.html"><strong>BehaviorSubject</strong></a> 🤘🏻 instead of a Subject here. A BehaviorSubject emits the previously emitted value to new subscribers. This can be really handy in an application. An example use case is fetching data from an API and emitting received value but only subscribing to the Subject after some time has passed.</p><p>This approach can solve race conditions 🏃🏻 in the event we are struggling to receive data quickly — for example during bootstrapping. Using this approach we still receive the previous value in case of a late subscription.</p><p>Notice that we initialize the BehaviorSubject but we expose it only as an Observable. The reason for this is to prevent emitting values outside the service and only allow values to be received on subscription.</p><p><a href="https://blog.angular-university.io/how-to-build-angular2-apps-using-rxjs-observable-data-services-pitfalls-to-avoid/">This article</a> does a great job of explaining Observable Data Services and especially the pitfalls that should be avoided.</p><p>At this stage, we will need an auth token for the API which can be obtained by registering <a href="https://www.football-data.org/client/register">here</a>. The free tier of 10 calls/minute will be enough for us since we only need the top competitions and we won’t make a ton of requests.</p><p>To finish up our service we add the API endpoint, league codes, and a function which makes a `get` request for the standings for a given league. We are only looking for the total matches played, so we take only the first element of the standings array.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60dad013a7898ab5ee583bad0fee9275/href">https://medium.com/media/60dad013a7898ab5ee583bad0fee9275/href</a></iframe><p>The only thing left to make the API call work is to add our auth token to the request header. I like using an interceptor in this case so if we decide to expand the application we do not need to add a token for each new request.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b33b2d7e0f47ea67bff6096481ff845/href">https://medium.com/media/4b33b2d7e0f47ea67bff6096481ff845/href</a></iframe><p>Our service is ready to fetch data and provide it, but we are really in need of a component that can consume it. Time to generate our standings component.</p><pre>ng g c standings</pre><p>First, let’s inject our service and make a request to get Premier League data when the component is initialized.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/472583ce06c3bf7a356c0eee43989bcd/href">https://medium.com/media/472583ce06c3bf7a356c0eee43989bcd/href</a></iframe><p>We inject the StandingService and initialize our <strong><em>teams$</em></strong> observable. As you can see, Premier League standings are fetched initially but we also have a <strong><em>getStandings</em></strong> method in case we would like to fetch data from other leagues.</p><p>The last step in building the application is to add a table and enable users to select which league they want to fetch. First, we add a <strong><em>mat-select</em></strong> and listen to selection change events and call <strong><em>getStandings</em></strong> with the value when another league is selected.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6cbb176d63dda2128d73c341b55bded/href">https://medium.com/media/c6cbb176d63dda2128d73c341b55bded/href</a></iframe><p>Next, we need a <strong><em>mat-table</em></strong> to display the standings. Here we’re able to pass an observable to the table so we can present new data in case a new value is emitted.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9dbb8165bb17b59fe1a90d6e62a33d69/href">https://medium.com/media/9dbb8165bb17b59fe1a90d6e62a33d69/href</a></iframe><p>To have our wonderful table ready we pass the <strong><em>$teams</em></strong> observable as a <strong><em>dataSource</em></strong> and define the columns.</p><p>At this point, all we need is to define the columns in our <strong><em>.ts</em></strong> file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc474a614f119a87df9bac00e1a0976f/href">https://medium.com/media/bc474a614f119a87df9bac00e1a0976f/href</a></iframe><p>Finally, a finishing touch. We add the gradient background (🦄) and a header so the whole site feels a bit cozier. The CSS and header component is in the <a href="https://github.com/AttilaMuller/football-standings">git repository</a> if you’d like to achieve the same look. (<em>Also do not forget to import the needed modules to </em><a href="https://github.com/AttilaMuller/football-standings/blob/master/src/app/app.module.ts"><em>app.module.ts</em></a><em>!</em>)</p><p>Aaand we’re done! We made a tiny fancy application that displays real-world data in record time! ☀️️</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2Facclaimeddependableassassinbug&amp;url=https%3A%2F%2Fgfycat.com%2Facclaimeddependableassassinbug-spongebob-squarepants-rainbow-burger&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FAcclaimedDependableAssassinbug-size_restricted.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=gfycat" width="1236" height="720" frameborder="0" scrolling="no"><a href="https://medium.com/media/543c6fae06ef6a88b3c85070d5997d04/href">https://medium.com/media/543c6fae06ef6a88b3c85070d5997d04/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c253068ed18" width="1" height="1" alt=""><hr><p><a href="https://medium.com/betsson-group/lets-build-a-small-application-using-observable-data-services-and-angular-8c253068ed18">Let’s build a small application using Observable Data Services and Angular!</a> was originally published in <a href="https://medium.com/betsson-group">Betsson Group</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>