<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Julian Dierkes</title>
    <description>The latest articles on DEV Community by Julian Dierkes (@juliandierkes).</description>
    <link>https://dev.to/juliandierkes</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F418791%2F1edee8dc-36b4-42cd-bcc9-1b78eac15e75.jpg</url>
      <title>DEV Community: Julian Dierkes</title>
      <link>https://dev.to/juliandierkes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/juliandierkes"/>
    <language>en</language>
    <item>
      <title>Automatically sync url path and query params with Angular component fields</title>
      <dc:creator>Julian Dierkes</dc:creator>
      <pubDate>Sun, 25 Jul 2021 14:23:02 +0000</pubDate>
      <link>https://dev.to/juliandierkes/automatically-sync-url-path-and-query-params-with-angular-component-fields-1eif</link>
      <guid>https://dev.to/juliandierkes/automatically-sync-url-path-and-query-params-with-angular-component-fields-1eif</guid>
      <description>&lt;p&gt;Wouldn't it be nice if a user of you Angular application could just send a link to another person ant they would end up seeing the exact same things on his screen?&lt;br&gt;
The user could also just bookmark the url and get back to the same view whenever he wants to.&lt;/p&gt;

&lt;p&gt;Using the Angular router you can accomplish that even if you have very dynamic views.&lt;br&gt;
However, the effort and boilerplate code for this is quite huge and can easily be avoided with a library I wrote. (My first npm package ❤️) &lt;/p&gt;

&lt;p&gt;The concept behind this is &lt;em&gt;deep linking&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is deep linking?
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;If you are already familiar with deep linking and how to implement it with the Angular Router continue here.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Imagine you have built a webapp for a library, and a user is browsing a list of available books. He selects a book and wants to show it to a friend. &lt;/p&gt;

&lt;p&gt;With deep linking the information of the selected book is part of the url and can easily be shared between users. The same thing can be done with any parameter that affects the current view in your Angular application. (e.g. additionally with a search string as shown below)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FNas3nmann%2Fngx-input-deep-linking%2Fmain%2Fapps%2Fdemo-book-list%2Fsrc%2Fassets%2Fdemo.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FNas3nmann%2Fngx-input-deep-linking%2Fmain%2Fapps%2Fdemo-book-list%2Fsrc%2Fassets%2Fdemo.gif" alt="Demo booklist"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As shown in the example above you can write these parameters to the url as&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;path parameter &lt;code&gt;library/:location/books/:selectedBookId&lt;/code&gt; or&lt;/li&gt;
&lt;li&gt;query parameter &lt;code&gt;...?searchString=jon&amp;amp;secondParameter=1&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Path parameters can be strings or numbers while query parameters also could be complex json objects&lt;/p&gt;

&lt;h2&gt;
  
  
  How to implement "deep linking" with the Angular router?
&lt;/h2&gt;

&lt;p&gt;In your components you can get the current path and query params by injecting the &lt;code&gt;ActivatedRouteSnapshot&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

export class YourComponent implements OnInit {
    private yourPathParam: number;
    private yourQueryParam: string;

    constructor(private readonly activatedRouteSnapshot: ActivatedRouteSnapshot) {}

    ngOnInit() {
        const pathParams: Params[] = this.activatedRouteSnapshot.params;
        this.yourPathParam = pathParams['yourPathParam'];

        const queryParams: Params[] = this.activatedRouteSnapshot.queryParams;
        this.yourQueryParam = queryParams['yourQueryParam'];
    }
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can even subscribe to changes in the url params by using the &lt;code&gt;ActivatedRoute&lt;/code&gt; instead of the &lt;code&gt;ActivatedRouteSnapshot&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

this.activatedRoute.params.subscribe((newPathParams) =&amp;gt; console.log(newPathParams));
this.activatedRoute.queryParams.subscribe((newQueryParams) =&amp;gt; console.log(newQueryParams));


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;What about the other way around? If a field in you component changes you can navigate to the new url by injecting the &lt;code&gt;Router&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

this.router.navigateByUrl(newUrl);


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The hard part here is figuring out the new url. You might not want to change existing parameters but ony change the one that is of interest in your component.&lt;br&gt;
However, this is a crucial part for implementing "deep linking" as we need an updated url whenever the view changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  The downsides of the Angular router
&lt;/h2&gt;

&lt;p&gt;As you can see synchronizing of url params with your component fields is quite hard and requires a lot of "boilerplate code".&lt;/p&gt;

&lt;p&gt;The problems of the Angular router are&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;not providing a way to linking url parameters to component inputs via configuration

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/angular/angular/issues/18967" rel="noopener noreferrer"&gt;A github issue&lt;/a&gt; for this requirement exists since 2017 &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;not providing a simple way to update the url on component field changes (e.g. via component outputs)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The simple way with ngx-deep-linking
&lt;/h2&gt;

&lt;p&gt;What if you could simply configure synchronization of component fields with the url?&lt;br&gt;
&lt;a href="https://www.npmjs.com/package/@jdrks/ngx-deep-linking" rel="noopener noreferrer"&gt;Ngx-deep-linking&lt;/a&gt; provides a way to do this in the route configuration.&lt;/p&gt;

&lt;p&gt;In the end you just need three things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You need to install &lt;strong&gt;@jdrks/ngx-deep-linking&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;npm install @jdrks/ngx-deep-linking&lt;/code&gt; or&lt;/li&gt;
&lt;li&gt;&lt;code&gt;yarn add @jdrks/ngx-deep-linking&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;You need to provide &lt;code&gt;@Input&lt;/code&gt; and &lt;code&gt;@Output&lt;/code&gt; for the fields you want to deep link.

&lt;ul&gt;
&lt;li&gt;You &lt;em&gt;must provide&lt;/em&gt; an &lt;code&gt;@Input&lt;/code&gt; to initially populate the component field and change it if the url changes&lt;/li&gt;
&lt;li&gt;You &lt;em&gt;may provide&lt;/em&gt; an &lt;code&gt;@Output&lt;/code&gt; to change the url whenever that component output emits. Make sure to follow the naming convention for Angular two way data binding by appending 'Change' to the field name.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;You need to provide a router config with the names of all fields you want to "deep link":

&lt;ul&gt;
&lt;li&gt;See example below&lt;/li&gt;
&lt;li&gt;You can use the provided interface &lt;code&gt;DeepLinkingRoute&lt;/code&gt; for a type safe configuration&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import {DeepLinkingRoute, DeepLinkingWrapperComponent} from '@jdrks/ngx-deep-linking';
...

const routes: DeepLinkingRoute[] = [
  {
    path: 'books/:selectedBookId',
    component: DeepLinkingWrapperComponent,
    wrappedComponent: BookListComponent,
    deepLinking: {
      params: [{name: 'selectedBookId', type: 'number'}],
      queryParams: [{name: 'searchString', type: 'string'}],
    }
  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class BookListRoutingModule {
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The book list component could look like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

@Component({
  templateUrl: 'book-list.component.html'
})
export class BookListComponent {

  private _selectedBookId: number = 0;

  @Output()
  private selectedBookIdChange: EventEmitter&amp;lt;number&amp;gt; = new EventEmitter&amp;lt;number&amp;gt;();

  @Input()
  get selectedBookId(): number {
    return this.selectedBookId;
  }

  set selectedBookId(value: number) {
    this.selectedBookId = value;
    this.selectedBookIdChange.next(bookId);
  }

  private _searchString = '';

  @Output()
  searchStringChange: EventEmitter&amp;lt;string&amp;gt; = new EventEmitter&amp;lt;string&amp;gt;();

  @Input()
  get searchString(): string {
    return this._searchString;
  }

  set searchString(value: string) {
    this._searchString = value;
    this.searchStringChange.next(value);
  }

  ...
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;So basically it's just like two-way data binding. The above implementation will automatically emit on the &lt;code&gt;@Output&lt;/code&gt; fields when using the setters, but this is just convenience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Features of ngx-deep-linking
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Easily synchronize your component fields with the url by simple route configuration&lt;/li&gt;
&lt;li&gt;Type safe configuration&lt;/li&gt;
&lt;li&gt;Supports synchronizing fields of type number, string and even complex types as json&lt;/li&gt;
&lt;li&gt;Supports lazy loading for Angular modules&lt;/li&gt;
&lt;li&gt;Supports hash routing strategy&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How does the library work under the hood?
&lt;/h2&gt;

&lt;p&gt;The library wraps you component into the &lt;code&gt;DeepLinkingWrapperComponent&lt;/code&gt;. The fields that should be "deep linked" are synced with the &lt;code&gt;DeepLinkingWrapperComponent&lt;/code&gt; via "manual" two-way data binding. The wrapper reacts to changes on both url and wrapped component and updates vice versa.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FNas3nmann%2Farticles%2Fmaster%2Fngx-deep-linking%2Fstructure.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FNas3nmann%2Farticles%2Fmaster%2Fngx-deep-linking%2Fstructure.png" alt="library structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;p&gt;Github: &lt;a href="https://github.com/Nas3nmann/ngx-deep-linking" rel="noopener noreferrer"&gt;https://github.com/Nas3nmann/ngx-deep-linking&lt;/a&gt;&lt;br&gt;
npm: &lt;a href="https://www.npmjs.com/package/@jdrks/ngx-deep-linking" rel="noopener noreferrer"&gt;https://www.npmjs.com/package/@jdrks/ngx-deep-linking&lt;/a&gt;&lt;/p&gt;

</description>
      <category>angular</category>
      <category>showdev</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>I built yesno.</title>
      <dc:creator>Julian Dierkes</dc:creator>
      <pubDate>Fri, 28 Aug 2020 16:23:10 +0000</pubDate>
      <link>https://dev.to/juliandierkes/i-built-yesno-5k5</link>
      <guid>https://dev.to/juliandierkes/i-built-yesno-5k5</guid>
      <description>&lt;p&gt;Hi everyone, &lt;/p&gt;

&lt;p&gt;while being quarantined for the last month i started a small project: &lt;a href="https://app-yesno.herokuapp.com/"&gt;&lt;strong&gt;yesno.&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is basically a webapp where you can anonymously ask yes/no question and everyone can anonymously answer them once before getting to see the yes/no statistics.&lt;br&gt;
It has a new and a top (of the last 48h) questions section.&lt;/p&gt;

&lt;p&gt;Technically I realized the Frontend Progressive Web App it with Angular and Ionic which was a great experience. The backend was written in Java with Spring Boot. Everything is deployed to heroku.&lt;/p&gt;

&lt;p&gt;I'm really hoping for feedback and I am open for any questions. (Even non-yesno questions 😉 )&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>angular</category>
      <category>javascript</category>
      <category>java</category>
    </item>
    <item>
      <title>D is for debounceTime</title>
      <dc:creator>Julian Dierkes</dc:creator>
      <pubDate>Tue, 18 Aug 2020 17:07:16 +0000</pubDate>
      <link>https://dev.to/juliandierkes/d-is-for-debouncetime-2435</link>
      <guid>https://dev.to/juliandierkes/d-is-for-debouncetime-2435</guid>
      <description>&lt;p&gt;Welcome back! Today it is time for... &lt;/p&gt;

&lt;p&gt;...two seconds later...&lt;/p&gt;

&lt;p&gt;No &lt;em&gt;NOW&lt;/em&gt; is time for...&lt;br&gt;
The &lt;a href="https://rxjs-dev.firebaseapp.com/api/operators/debounceTime"&gt;debounceTime&lt;/a&gt; operator!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;What does it do?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It takes your source observable and starts a timer when a value is emitted. (The time is specified in milliseconds)&lt;br&gt;
If no new value occurs before the timer finishes, &lt;code&gt;debounceTime&lt;/code&gt; emits the value. &lt;br&gt;
If a new value occurs nothing is emitted and the timer is reset and started again.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;What kind of problems does this solve?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It is mostly used for performance improvements, e.g.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;A line chart with panning and/or zooming functionality. You don't want to fetch new data on every pan/zoom interaction. Instead you want to fetch the data when the users has stopped scrolling or panning for a specified amount of time.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;zoomChanged
    .pipe(debounceTime(200))
    .subscribe(newTimeWindow =&amp;gt; fetchChartData(newTimeWindow))
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Fetching data for an autocomplete input. You don't want to fetch the autocomplete data matching the current user input on each character the user enters. You want to fetch them when the users stops typing for a specified amount of time.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;userInputChanged
    .pipe(debounceTime(200))
    .subscribe(userInput =&amp;gt; fetchFilteredAutocompleteValues(userInput))
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Pretty useful right?&lt;/p&gt;

&lt;p&gt;Stay tuned for more RxJS glory!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Do we need JS naming conventions in TS?</title>
      <dc:creator>Julian Dierkes</dc:creator>
      <pubDate>Tue, 11 Aug 2020 09:58:51 +0000</pubDate>
      <link>https://dev.to/juliandierkes/do-we-need-js-naming-conventions-in-ts-6ml</link>
      <guid>https://dev.to/juliandierkes/do-we-need-js-naming-conventions-in-ts-6ml</guid>
      <description>&lt;p&gt;I tend to ignore JavaScript naming conventions that are based on visibility or type like "_aPrivateVariable" or "anObservable$", because they are already transparent through the use of Typescript. &lt;br&gt;
How do you handle these naming conventions and why?&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>javascript</category>
      <category>typescript</category>
    </item>
    <item>
      <title>C is for combineLatest</title>
      <dc:creator>Julian Dierkes</dc:creator>
      <pubDate>Sun, 09 Aug 2020 15:27:07 +0000</pubDate>
      <link>https://dev.to/juliandierkes/c-is-for-combinelatest-5ge</link>
      <guid>https://dev.to/juliandierkes/c-is-for-combinelatest-5ge</guid>
      <description>&lt;p&gt;Let's check out the first function in this series: &lt;a href="https://rxjs-dev.firebaseapp.com/api/index/function/combineLatest"&gt;combineLatest&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Use this function whenever you are interested in the latest output of two or more Observables.&lt;/p&gt;

&lt;p&gt;One can understand the behavior pretty good when looking at the marble diagram from the official documentation. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oV9GYw4w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://rxjs-dev.firebaseapp.com/assets/images/marble-diagrams/combineLatest.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oV9GYw4w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://rxjs-dev.firebaseapp.com/assets/images/marble-diagrams/combineLatest.png" alt="Marble diagram of combineLatest" width="800" height="463"&gt;&lt;/a&gt;&lt;br&gt;
The upper observables emit the values in the marbles and are combined with combineLatest. As you can see it emits tha latest values of all its Observables whenever on of them emits. These values are then returned as array.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Enough theory! Show us the example!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Ok. I first used this operator in the following scenario:&lt;/p&gt;

&lt;p&gt;We had a relational database with a many-to-many relationship and two different models that had to be consolidated and displayed in the UI written in Angular. Lets use &lt;code&gt;Course&lt;/code&gt; and &lt;code&gt;Student&lt;/code&gt; as examples here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Course&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;studentIds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Student&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However the model we want to display should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;CourseWithStudents&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;students&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Student&lt;/span&gt;&lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So we need to merge both models into one view model. &lt;/p&gt;

&lt;p&gt;Lets have a look on how to achieve this with the &lt;code&gt;combineLatest&lt;/code&gt; operator.&lt;/p&gt;

&lt;p&gt;We have two Angular services providing the data in form of an Observable, the &lt;code&gt;CourseService&lt;/code&gt; and the &lt;code&gt;StudentService&lt;/code&gt;.&lt;br&gt;
I'm also simulating some http delay in the services using &lt;code&gt;setTimeout()&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;CourseService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;_courses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Course&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;German&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;studentIds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;3&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;4&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Math&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;studentIds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;3&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;5&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;3&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Biology&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;studentIds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;
  &lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="nl"&gt;courses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;BehaviorSubject&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Course&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;BehaviorSubject&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Course&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;([]);&lt;/span&gt;

  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;courses&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_courses&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;StudentService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;_students&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Student&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Johnny Rakete&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Melissa Woods&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;3&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Gordon Thorner&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;4&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jamy Dormer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;5&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Will Higgs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;6&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Smantha Claire Restful&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="nl"&gt;students&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;BehaviorSubject&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Student&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;BehaviorSubject&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Student&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;([]);&lt;/span&gt;

  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;students&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_students&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the code that combines both Observable results once any of them emits:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;coursesWithStudents&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;combineLatest&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;courseService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;courses&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;studentService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;students&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;tap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;latestResults&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;combineLatest emitted&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;latestResults&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;latestResults&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;latestCourses&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;latestStudents&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;latestResults&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;latestCourses&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;course&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;course&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;course&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;students&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;latestStudents&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;student&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;course&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;studentIds&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;student&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
      &lt;span class="p"&gt;}));&lt;/span&gt;
    &lt;span class="p"&gt;}));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is basically just the &lt;code&gt;combineLatest&lt;/code&gt; operator with some mapping logic attached. The whole code returns an Observable which we can consume e.g. with the &lt;code&gt;async&lt;/code&gt; pipe directly in the template.&lt;/p&gt;

&lt;p&gt;Lets see the output of the above code in three tables, one for courses, one for students and one for the combined result.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EBn5X3T_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://raw.githubusercontent.com/Nas3nmann/articles/master/rxjs/the%2520ABCs%2520of%2520rxjs/images/462862b670af6a22c067205d1c328f8c.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EBn5X3T_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://raw.githubusercontent.com/Nas3nmann/articles/master/rxjs/the%2520ABCs%2520of%2520rxjs/images/462862b670af6a22c067205d1c328f8c.gif" alt="resulting tables" width="800" height="499"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I've also integrated some console logging which pops up after the service timeouts emit. You can see that our merged Observable emits three times.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When the initial empty arrays are emitted by the BehaviorSubjects &lt;/li&gt;
&lt;li&gt;When the courses array is emitted&lt;/li&gt;
&lt;li&gt;When the students array is emitted&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qXAc5nUq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raw.githubusercontent.com/Nas3nmann/articles/master/rxjs/the%2520ABCs%2520of%2520rxjs/images/2094c4e1033e28194b5b94bb07bb38ed.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qXAc5nUq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raw.githubusercontent.com/Nas3nmann/articles/master/rxjs/the%2520ABCs%2520of%2520rxjs/images/2094c4e1033e28194b5b94bb07bb38ed.png" alt="console output" width="761" height="763"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So we achieved what was desired. Every time the courses or students are updated the resulting table gets a fresh merged view model.&lt;/p&gt;

&lt;p&gt;Thanks for reading! Feel free to check out the other articles of this series and stay tuned for the next ones.&lt;/p&gt;

</description>
      <category>rxjs</category>
      <category>javascript</category>
      <category>angular</category>
      <category>webdev</category>
    </item>
    <item>
      <title>B is for BehaviorSubject</title>
      <dc:creator>Julian Dierkes</dc:creator>
      <pubDate>Sat, 08 Aug 2020 14:43:45 +0000</pubDate>
      <link>https://dev.to/juliandierkes/the-abcs-of-rxjs-2-21c0</link>
      <guid>https://dev.to/juliandierkes/the-abcs-of-rxjs-2-21c0</guid>
      <description>&lt;p&gt;Well i think most of you have already heard about the &lt;a href="https://rxjs-dev.firebaseapp.com/api/index/class/BehaviorSubject"&gt;BehaviorSubject&lt;/a&gt;. In case you didn't or want a quick refresh keep reading.&lt;br&gt;
 The BehaviorSubject, just like the normal Subject, emits values to its Observers, but there are two main differences:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It has an initial value&lt;/li&gt;
&lt;li&gt;It emits its current value to new subscribers&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;What is it good for?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;State management for example. &lt;/p&gt;

&lt;p&gt;Here you mostly want an initial state, notifications for observers on changes and you also want to receive the current state on any later subscription.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Ok... That's all? This is your example?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Fine let's be more practical:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A data table. You want the data array that its based on to always be defined. Just use the BehaviorSubject with an initial value of [] and fetch or add some data whenever you feel like doing it. Even if the table subscribes after adding/fetching data the table will immediately receive the current state/data. &lt;/li&gt;
&lt;li&gt;A toggle switch. It has an initial value of false so its deactivated. You want to notify several other components about changes. Even components created after the toggle (and therefore subscribing after the toggle state may have changed) will get the current value of the BehaviorSubject.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>rxjs</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>A is for AsyncSubject</title>
      <dc:creator>Julian Dierkes</dc:creator>
      <pubDate>Sat, 08 Aug 2020 14:06:04 +0000</pubDate>
      <link>https://dev.to/juliandierkes/the-abcs-of-rxjs-1-165p</link>
      <guid>https://dev.to/juliandierkes/the-abcs-of-rxjs-1-165p</guid>
      <description>&lt;p&gt;The &lt;a href="https://rxjs-dev.firebaseapp.com/api/index/class/AsyncSubject"&gt;AsyncSubject&lt;/a&gt; is a lesser known sub class of &lt;a href="https://rxjs-dev.firebaseapp.com/api/index/class/Subject"&gt;Subject&lt;/a&gt;, that emits only its last value to its Observers once (and only if) it completes.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;But isn't that the same thing as using a Subject and the &lt;a href="https://www.learnrxjs.io/learn-rxjs/operators/filtering/last"&gt;last&lt;/a&gt; operator?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Nearly, but the AsyncSubject is designed for multicast usage (multiple Observers) and the behavior differs for Observers that subscribe after completion.&lt;br&gt;
The value is also emitted to Observers subscribing &lt;strong&gt;after&lt;/strong&gt; the AsyncSubject has already completed, which does not happen when using a simple Subject.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;When would I need such a Subject?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For example this could be handy for implementing something containing HTTP requests. Knowing that http request will only have a single result it totally makes sense to use an AsyncSubject because:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It will only emit a single value&lt;/li&gt;
&lt;li&gt;It completes, so there is no need for the Observers to unsubscribe&lt;/li&gt;
&lt;li&gt;Other Observers can even subscribe &lt;strong&gt;after&lt;/strong&gt; the request has finished&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>rxjs</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Provider Scopes in Angular</title>
      <dc:creator>Julian Dierkes</dc:creator>
      <pubDate>Sat, 04 Jul 2020 13:31:51 +0000</pubDate>
      <link>https://dev.to/juliandierkes/provider-scopes-in-angular-209g</link>
      <guid>https://dev.to/juliandierkes/provider-scopes-in-angular-209g</guid>
      <description>&lt;h3&gt;
  
  
  Angular Level:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FNas3nmann%2Farticles%2Fb09b6860c561037e223a104a6e824c371b7444ec%2FAngular%2Fshared%2Fangular-levels%2Fng_2_of_5.svg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FNas3nmann%2Farticles%2Fb09b6860c561037e223a104a6e824c371b7444ec%2FAngular%2Fshared%2Fangular-levels%2Fng_2_of_5.svg" alt="level" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Angular's modular system provides you with the ability to create &lt;em&gt;Components&lt;/em&gt; and &lt;em&gt;Services&lt;/em&gt;.&lt;br&gt;
While Components should be focused on the view, meaning the html template, a Service should be used for the application logic. While, from my experience, they are mostly used for HTTP requests, Services mayfulfill other purposes as logging or validation. Many Services will be reused throughout one application.&lt;/p&gt;

&lt;p&gt;When reusing Services, it is important to think about &lt;strong&gt;the scope&lt;/strong&gt;, in which you want to provide it.&lt;/p&gt;

&lt;p&gt;Angular basically offers three scopes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Root Scope&lt;/li&gt;
&lt;li&gt;Module Scope&lt;/li&gt;
&lt;li&gt;Component Scope&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  The Root Scope
&lt;/h2&gt;

&lt;p&gt;The root scope is the most commonly used scope for providing Services as it is also the default scope when creating a Service via Angular CLI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Injectable&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;providedIn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ExampleService&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The default &lt;code&gt;providedIn&lt;/code&gt; argument in the CLI generated Service above means that the Service will be provided in the application root, the AppModule. Therefore the Service will be a singleton, meaning that there will be only one instance of this Service even if it is injected in multiple Modules and used in multiple Components or Directives. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hint: Using the &lt;code&gt;providedIn&lt;/code&gt; argument in &lt;code&gt;@Injectable&lt;/code&gt; can also optimize bundle sizes if a service isn't used, which is especially useful for writing libraries. More info in the &lt;a href="https://angular.io/guide/hierarchical-dependency-injection#tree-shaking-and-injectable" rel="noopener noreferrer"&gt;Angular Docs&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Module Scope
&lt;/h2&gt;

&lt;p&gt;The same way we can provide the Service in Module scope:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Injectable&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;providedIn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ExampleModule&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ExampleService&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But what if we don't want to share the service between modules? &lt;br&gt;
We can then (instead of &lt;code&gt;provideIn&lt;/code&gt;) use the providers array in the corresponding &lt;code&gt;@NgModule&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;NgModule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;
  &lt;span class="na"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;ExampleService&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ExampleModule&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way an instance of the service is created for the Module. If the service is added to the &lt;code&gt;providers&lt;/code&gt; array of multiple Modules, each Module gets its own Service instance.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Component Scope
&lt;/h2&gt;

&lt;p&gt;We can also create an individual Service instance for a Component by using the Component scope:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;
  &lt;span class="na"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;ExampleService&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ExampleComponent&lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Let's see this in action
&lt;/h2&gt;

&lt;p&gt;Let's get our hands dirty and create an example application using &lt;strong&gt;Module Scope&lt;/strong&gt; and &lt;strong&gt;Component Scope&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I've used the Angular CLI to create a project with the following structure:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FNas3nmann%2Farticles%2Fmaster%2FAngular%2Fprovider-scope%2Fexample-project-tree.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FNas3nmann%2Farticles%2Fmaster%2FAngular%2Fprovider-scope%2Fexample-project-tree.png" alt="Project structure" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is only one Service, which is located in the &lt;code&gt;SharedModule&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Injectable&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ExampleService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Frank&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This Module and therefore the Service is used two other modules which both are then imported in the &lt;code&gt;AppModule&lt;/code&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;The &lt;code&gt;ComponentScopeModule&lt;/code&gt; which uses the &lt;strong&gt;Component Scope&lt;/strong&gt; and consists of two components&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;ExampleComponent1&lt;/code&gt; which provides an input for the service's property &lt;code&gt;name&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;component-scope-example1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`&amp;lt;input [(ngModel)]="service.name"&amp;gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;ExampleService&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Example1Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nx"&gt;service&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ExampleService&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;ExampleComponent2&lt;/code&gt; which just displays the service's property &lt;code&gt;name&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;component-scope-example2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`&amp;lt;p&amp;gt;{{service.name}}&amp;lt;/p&amp;gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;ExampleService&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Example2Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nx"&gt;service&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ExampleService&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;The &lt;code&gt;ModuleScopeModule&lt;/code&gt; which uses the &lt;strong&gt;Module Scope&lt;/strong&gt; and consists of two similar components.&lt;br&gt;
The difference is, that the Components don't use the &lt;code&gt;providers&lt;/code&gt; array. Instead the Service is provided &lt;br&gt;
in the Module:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;NgModule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;declarations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;Example1Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Example2Component&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;imports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;CommonModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;SharedModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;FormsModule&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;Example1Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;Example2Component&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;ExampleService&lt;/span&gt;     &lt;span class="o"&gt;&amp;lt;---&lt;/span&gt; &lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;s provided here instead
  ]
})
export class ModuleScopeModule {
}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt;All four Components are then displayed using the &lt;code&gt;AppComponent&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Module Scoped&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;module-scope-example1&amp;gt;&amp;lt;/module-scope-example1&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;module-scope-example2&amp;gt;&amp;lt;/module-scope-example2&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Component Scoped&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;component-scope-example1&amp;gt;&amp;lt;/component-scope-example1&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;component-scope-example2&amp;gt;&amp;lt;/component-scope-example2&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And finally this is what we get:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FNas3nmann%2Farticles%2Fmaster%2FAngular%2Fprovider-scope%2Fexample_served.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FNas3nmann%2Farticles%2Fmaster%2FAngular%2Fprovider-scope%2Fexample_served.gif" alt="Result in action" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can see that in the "Module Scoped" section both components use the same service and therefore the input of the first component changes the output of the second component.&lt;br&gt;
In the "Component Scoped" section this does not work as there are two service instances created, &lt;br&gt;
one for each component.&lt;/p&gt;




&lt;p&gt;Thanks for reading!&lt;/p&gt;

&lt;p&gt;Cheers Julian&lt;/p&gt;

</description>
      <category>angular</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Where/How do you get your ideas?</title>
      <dc:creator>Julian Dierkes</dc:creator>
      <pubDate>Sat, 04 Jul 2020 10:49:47 +0000</pubDate>
      <link>https://dev.to/juliandierkes/where-how-do-you-get-your-ideas-1p1i</link>
      <guid>https://dev.to/juliandierkes/where-how-do-you-get-your-ideas-1p1i</guid>
      <description>&lt;p&gt;Hi @all,&lt;br&gt;
I currently have a lot of time to learn and try new things and would like to use all that new stuff on real world appications. But I am struggling with ideas for libraries/apps that really bring value to someone.&lt;br&gt;
How do you come up with ideas for such stuff?&lt;/p&gt;

&lt;p&gt;I'm thankful for any input on this topic.&lt;/p&gt;

&lt;p&gt;Cheers Julian&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>help</category>
    </item>
    <item>
      <title>Two Ways of Using Angular Services With the HttpClient</title>
      <dc:creator>Julian Dierkes</dc:creator>
      <pubDate>Thu, 02 Jul 2020 16:39:35 +0000</pubDate>
      <link>https://dev.to/juliandierkes/two-ways-of-using-angular-services-with-the-httpclient-51ef</link>
      <guid>https://dev.to/juliandierkes/two-ways-of-using-angular-services-with-the-httpclient-51ef</guid>
      <description>&lt;h3&gt;
  
  
  Angular Level:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qkXme4rq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raw.githubusercontent.com/Nas3nmann/articles/b09b6860c561037e223a104a6e824c371b7444ec/Angular/shared/angular-levels/ng_3_of_5.svg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qkXme4rq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raw.githubusercontent.com/Nas3nmann/articles/b09b6860c561037e223a104a6e824c371b7444ec/Angular/shared/angular-levels/ng_3_of_5.svg" alt="level" width="800" height="185"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  The Old Fashioned Way: The 'Pull' Approach
&lt;/h1&gt;

&lt;p&gt;When starting to build an Angular app you most likely come to the point where you need some kind of HTTP communication.&lt;br&gt;
I guess every intermediate Angular user has used the http client before. &lt;br&gt;
Most likely it was wrapped in an Angular service. &lt;br&gt;
E.g. a service for a shopping list app could look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Injectable&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;providedIn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;ShoppingListPullService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="nx"&gt;ITEMS_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;assets/items.json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;httpClient&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;HttpClient&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;getItems&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;Observable&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ShoppingItem&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;httpClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ShoppingItem&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ITEMS_URL&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A component then gets the shopping items via a simple method call, stores them and can display them like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;app-pull&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
      &amp;lt;div *ngFor="let user of items"&amp;gt;
          - {{user.quantity}} {{user.name}}
      &amp;lt;/div&amp;gt;
  `&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;PullComponent&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;OnInit&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="nl"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ShoppingItem&lt;/span&gt;&lt;span class="p"&gt;[];&lt;/span&gt;

  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nx"&gt;shoppingListService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ShoppingListPullService&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;ngOnInit&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;shoppingListService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getItems&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that we don't need to &lt;code&gt;unsubscribe&lt;/code&gt; here, as the angular &lt;code&gt;HttpClient&lt;/code&gt; handles this for us.&lt;br&gt;
If we had another kind of Observable here, we would also need to &lt;code&gt;unsubscribe&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let's call this approach the "Pull Approach", because it pulls the data from the service and the component is responsible for holding the state (in this case the array of shopping items).&lt;br&gt;
After any possible change of the items a refetch must be done including the corresponding subscribe block.&lt;/p&gt;

&lt;p&gt;This approach is nice and simple, but may not be suitable if multiple components use the service and all of them should share one consistent state.&lt;br&gt;
E.g. imagine you have a component for listing the items and one component for adding new items.&lt;br&gt;
Both components need control of the list.&lt;/p&gt;
&lt;h1&gt;
  
  
  Observable Data Service: The 'Push' Approach
&lt;/h1&gt;

&lt;p&gt;Here an "Observable Data Service" or "Service With a Subject" is much more convenient.&lt;br&gt;
 It may look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Injectable&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;providedIn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;ShoppingListPushService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="nx"&gt;ITEMS_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/assets/items.json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nx"&gt;items$&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;BehaviorSubject&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ShoppingItem&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;BehaviorSubject&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ShoppingItem&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;([]);&lt;/span&gt;

  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;httpClient&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;HttpClient&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;fetchList&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;httpClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ShoppingItem&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ITEMS_URL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;receivedItems&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;receivedItems&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;Observable&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ShoppingItem&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;asObservable&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's have a look on how this works:&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;fetchList&lt;/code&gt; method executes an HTTP request.&lt;br&gt;
After it returned the items successfully they are &lt;em&gt;published&lt;/em&gt; to the &lt;a href="https://www.learnrxjs.io/learn-rxjs/subjects/behaviorsubject"&gt;BehaviourSubject&lt;/a&gt; &lt;code&gt;items$&lt;/code&gt;, which means that anyone subscribed to this subject will get that new array of items.&lt;br&gt;
This Subject is made public in the form of an &lt;a href="https://rxjs-dev.firebaseapp.com/guide/observable"&gt;Observable&lt;/a&gt; by the &lt;code&gt;get&lt;/code&gt; method below so nothing can be published from outside of the service.&lt;/p&gt;

&lt;p&gt;This kind of service can easily be used with the Angular &lt;code&gt;async&lt;/code&gt; pipe. &lt;br&gt;
No need to &lt;code&gt;subscribe&lt;/code&gt; to or &lt;code&gt;unsubscribe&lt;/code&gt; from anything.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;app-push&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
      &amp;lt;div *ngFor="let item of shoppingListService.items | async"&amp;gt;
          - {{item.quantity}} {{item.name}}
      &amp;lt;/div&amp;gt;
  `&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;PushComponent&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;OnInit&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nx"&gt;shoppingListService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ShoppingListPushService&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;ngOnInit&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;shoppingListService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fetchList&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only thing left to do programmatically in the list component is to trigger the data fetch.&lt;/p&gt;

&lt;p&gt;So let's again imagine a second component using this service to add items to the shopping list. &lt;br&gt;
After adding an item the component may easily trigger the &lt;code&gt;fetchList()&lt;/code&gt; method and cause an update of the item list in the other component.&lt;/p&gt;

&lt;p&gt;Pretty easy, huh?&lt;/p&gt;

</description>
      <category>angular</category>
      <category>rxjs</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
