#How do I access a component's function in service
1 messages · Page 1 of 1 (latest)
So that in your component, you can do
this.connectionService.someObservableUsedToNotify.subscribe(() => {
// call any method from the component here
})
I can try and help u, if you elaborate where in there service you want to communicate back to the component
in the app.component.ts file, I want access the displayInternetPopUp method which is in the service
isThereInternet() {
return this.connectionService.status === true
? this.displayInternetPopUp()
: false;
}
For that to happen, I have to access the ngOnInit in the component
@wheat tangle
I dont think I understand
For that to happen, I have to access the ngOnInit in the component
If u need to access a service method from a component, u just call the method.
Yeah but first I need to access the ngOnInit of the component right
for the displayInternetPopUp function to work
I am not sure I understand what u mean.
You should never call a component's method from inside a service.
So you are saying that we cannot access a component's method inside a service right?
Yes.
And I am also saying you shouldnt need to.
If you explain what you want to achieve, and not how you think you need to achieve it, we can try and help.
I want to make use of service to check whether Internet is there or not
And it will bring up a popup component
which is serverResponseDisplayService
and in that there is button to try again
when a user clicks that button, the page should be refreshed
this.serverResponseDisplayService.messageDisplaySubscribableFromPopUp
.pipe(take(1))
.subscribe(data => {
if (data === 'retry') {
this.ngOnInit();
}
});
}
And which of that requires to call ngOnInit?
yes
That wasn't a yes/no question tho 😄
So what you can do is:
export class InternetCheckService {
status: boolean = false;
isConnected: boolean = true;
reloadSubject = new Subject();
reload$ = reloadSubject.asObservable();
displayInternetPopUp() {
this.serverResponseDisplayService.errorMessageToShow({
title: 'No internet connection.',
buttonText: 'Close',
message: 'Please try again later or try refreshing the page.',
});
this.serverResponseDisplayService.messageDisplaySubscribableFromPopUp
.pipe(take(1))
.subscribe(data => {
if (data === 'retry') {
this.reloadSubject.next();
}
});
}
}
And in your component, use:
export class AppComponent {
constructor(private readonly connectionService: InternetCheckService){}
ngOnInit() {
this.loadData();
this.connectionService.reload$.subscribe(() => {
this.loadData();
});
}
loadData() {
this.registerLocale();
this.subscribeToTitleService();
this.documentOrientationListener();
}
}
However, you shouldnt need to call all those methods again.
But anyway, this should achieve what you are asking for.
Be sure to unsubscribe any previous subscription when you resubscribe like that.
How to unsubscribe it?
calling unsubscribe.
oh okay
An error is occuring in this.reloadSubject.next();
Subject.d.ts(32, 10): An argument for 'value' was not provided.
new Subject<void>
When I do that , i get this error
error TS2532: Object is possibly 'undefined'.
Where
Error: Module parse failed: Unexpected token (35:56)
File was processed with these loaders:
- ./node_modules/@angular-devkit/build-angular/src/babel/webpack-loader.js
- ./node_modules/@angular-devkit/build-angular/src/babel/webpack-loader.js
- ./node_modules/@ngtools/webpack/src/ivy/index.js
You may need an additional loader to handle the result of these loaders.
| constructor() {
| this.isConnectedToInternet = true;
this.reloadSubject = new rxjs_2.Subject < void >
| reload$;
| }
@wheat tangle
I cant see how that error relates to what we talked about.
error TS2532: Object is possibly 'undefined'.
13 reloadSubject = new Subject<void>
It's on the edit you told me to do
new Subject<void>
What is possibly undefined ?
reloadSubject
Please share the code that introduces this
import {Injectable} from '@angular/core';
import {ConnectionService} from 'ng-connection-service';
import {ServerResponseDisplayService} from '@components/ui/server-response-display/server-response-display-service/server-response-display.service';
import {take} from 'rxjs';
import {Subject} from 'rxjs';
@Injectable({
providedIn: 'root',
})
export class InternetCheckService {
isConnectedToInternet = true;
reloadSubject = new Subject<void>
reload$ = this.reloadSubject.asObservable();
constructor(
private connectionService: ConnectionService,
private serverResponseDisplayService: ServerResponseDisplayService
) {
this.connectionService.monitor().subscribe(isConnected => {
this.isConnectedToInternet = isConnected.hasInternetAccess;
if (!this.isConnectedToInternet) {
this.displayNoInternetMessage();
}
});
}
displayNoInternetMessage() {
this.serverResponseDisplayService.errorMessageToShow({
title: 'No internet connection.',
buttonText: 'Close',
message: 'Please try again later or try refreshing the page.',
});
this.serverResponseDisplayService.messageDisplaySubscribableFromPopUp
.pipe(take(1))
.subscribe(data => {
if (data === 'retry') {
this.reloadSubject.next();
}
});
}
}
And which line is giving that error ?
this.reloadSubject.next();
I dont see why that would give that error
wait a min
Small edition in code
Now there are no erros in the code
But in terminal lots of errors are coming
Most of them are showing this error
error TS2532: Object is possibly 'undefined'.
13 reloadSubject = new Subject<void>
error TS2532: Object is possibly 'undefined'.
14 reload$ = this.reloadSubject.asObservable();
Object is possibly 'undefined'.
28 this.serverResponseDisplayService.errorMessageToShow({
Object is possibly 'undefined'.
34 this.serverResponseDisplayService.messageDisplaySubscribableFromPopUp
error TS2532: Object is possibly 'undefined'.
38 this.reloadSubject.next();
Do you have any other solution to overcome this errors? @wheat tangle
Did you try restarting the terminal ?
let me try that
Yup I did that, still all of the errors are coming
Error: Module parse failed: Unexpected token (35:56)
File was processed with these loaders:
- ./node_modules/@angular-devkit/build-angular/src/babel/webpack-loader.js
- ./node_modules/@angular-devkit/build-angular/src/babel/webpack-loader.js
- ./node_modules/@ngtools/webpack/src/ivy/index.js
You may need an additional loader to handle the result of these loaders.
| constructor() {
| this.isConnectedToInternet = true;
this.reloadSubject = new rxjs_2.Subject < void >
| reload$;
| }
This is the first error which pops up
As mentioned, I cant see how the changed we talked about can cause that.
When I change reloadSubject = new Subject<void> to reloadSubject = new Subject(), all the errors go away
error TS2554: Expected 1 arguments, but got 0.
38 this.reloadSubject.next();
~~~~~~
node_modules/rxjs/dist/types/internal/Subject.d.ts:32:10
32 next(value: T): void;
~~~~~~~~
An argument for 'value' was not provided.
and only this error is shown
Any other way we can tackle this problem @wheat tangle
I cant see how the change we talked about can cause that.
Based on what you shared, I cant be helpful.
I found out the problem
We had to add new Subject<void>();
@wheat tangle
But when I click the try again button it does not load the ngOnInit
The popup is not getting loaded again
U already had that ?
I did'nt put ()
Do you have any idea why ngOnInit is not loading when try button is clicked @wheat tangle
Can you show your component
app.component.html
<div class="app-container">
<app-server-response-display></app-server-response-display>
<router-outlet></router-outlet>
</div>
I Mean the one about the oninit
import {Component, HostListener} from '@angular/core';
import {ActivatedRoute, Data, NavigationEnd, Router} from '@angular/router';
import {Title} from '@angular/platform-browser';
import {filter} from 'rxjs/operators';
import {TitleService} from '@services/title/title.service';
import {registerLocaleData} from '@angular/common';
import localeDe from '@angular/common/locales/de';
import {InternetCheckService} from '@services/internet-check/internet-check.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {
title = 'admin';
initialHeight = 0;
previousOrientation: any;
currentOrientation: any;
constructor(
private router: Router,
private activatedRoute: ActivatedRoute,
private toolbarTitle: Title,
private toolbarTitleService: TitleService,
private readonly internetCheckService: InternetCheckService
) {}
ngOnInit() {
this.registerLocale();
this.subscribeToTitleService();
this.documentOrientationListener();
}
get isMobileDevice() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent
);
}
registerLocale() {
registerLocaleData(localeDe, 'de');
}
subscribeToTitleService() {
this.router.events
.pipe(filter(event => event instanceof NavigationEnd))
.subscribe(() => {
const route = this.getChild(this.activatedRoute);
route.data.subscribe((data: Data) => {
this.toolbarTitle.setTitle(
this.toolbarTitleService.getFormattedTitleName(data.title)
);
});
});
}
Where is the part that subscribes on the observable?
This
I dont see it ?
this
import {Component, HostListener} from '@angular/core';
import {ActivatedRoute, Data, NavigationEnd, Router} from '@angular/router';
import {Title} from '@angular/platform-browser';
import {filter} from 'rxjs/operators';
import {TitleService} from '@services/title/title.service';
import {registerLocaleData} from '@angular/common';
import localeDe from '@angular/common/locales/de';
import {UtilsService} from '@services/utils/utils.service';
import {InternetCheckService} from '@services/internet-check/internet-check.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {
title = 'admin';
initialHeight = 0;
previousOrientation: any;
currentOrientation: any;
constructor(
private router: Router,
private activatedRoute: ActivatedRoute,
private utils: UtilsService,
private toolbarTitle: Title,
private toolbarTitleService: TitleService,
private readonly internetCheckService: InternetCheckService
) {}
ngOnInit() {
this.loadData();
this.internetCheckService.reload$.subscribe(() => {
this.loadData();
});
}
loadData() {
this.registerLocale();
this.subscribeToTitleService();
this.documentOrientationListener();
}
registerLocale() {
registerLocaleData(localeDe, 'de');
}
This is the code now
And what is not working ?
when I click try again button in the popup, it should load ngOnInit right
yeah loadData
it is not calling it
I added dummy text in loadData and console logged it
the text is not shown in console
Okay, its hard to tell.
Would be useful if you can start reproducing this on stackblitz, that way we can help.
ok let me try that
Hey @wheat tangle , I copied all of the code required to run into stackblitz but the website is not loading. Could you check where I'm going wrong?
A angular-cli project based on @angular/animations, @angular/common, @angular/compiler, @angular/core, @angular/forms, @angular/platform-browser, @angular/platform-browser-dynamic, @angular/router, core-js, rxjs, tslib and zone.js.
Could you turn off the wifi and see if the internet check works
I saved it, still no content is shown
what service
InternetCheck
the service is used in the app.component.ts file
yeah
I redirected index.html, component loader to app-loader
which redirects to app.component.ts
No idea what you are saying
but the stackblitz isnt bootstrapping your app component
please fix that
ok
there is bootstrapApplication
it's using the App from inside main.ts. Not yours.
Fix that.
- move your app component in the src folder
- make app component standalone
- import app component in main.ts
- use it to pass to bootstrapApplication
- remove App from main.ts
You didnt do what I said above...
I can't import and export appComponent in the same file
No idea what you mean.
import 'zone.js/dist/zone';
import { Component, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from 'src/app/app.component';
@Component({
selector: 'my-app',
standalone: true,
imports: [CommonModule],
template: `
<h1>Hello from {{name}}!</h1>
<a target="_blank" href="https://angular.io/start">
Learn more about Angular
</a>
`,
})
export class AppComponent{
name = 'Angular';
}
bootstrapApplication(AppComponent);
When i do this in main.ts
Individual declarations in merged declaration 'AppComponent' must be all exported or all local.
i get this error
You told to remove App
It was named App ye.
yeah I replaced App with AppComponent
I said remove, not replace.
Still I'm getting no display
What if u refresh ?
I also configured the application like this:
bootstrapApplication(AppComponent, {
providers: [
provideHttpClient(),
{
provide: ConnectionService,
useValue: {
monitor: () => of({ hasInternetAccess: false }),
},
},
],
});
so u do not need to disable wifi.
It runs as if there is no wifi.
But I cant see anything in that code that would show a popup or so.
but there is a we have to check whether the popup is coming while there the internet is on
I have no idea what your code should do.
check internet-check.service
But the internet check works.
Yes that doesnt show a popup
displayNoInternetMessage() {
this.serverResponseDisplayService.errorMessageToShow({
title: 'No internet connection.',
buttonText: 'Close',
message: 'Please try again later or try refreshing the page.',
});
this.serverResponseDisplayService.messageDisplaySubscribableFromPopUp
.pipe(take(1))
.subscribe((data) => {
if (data === 'retry') {
this.reloadSubject.next();
}
});
}
That doesnt display anything
serverResponseDisplayService is used for displaying the popup
Its not.
do you see the popup?
??
There is nothing that shows a popup.
Its not that the popup isnt showing.
There is no code that shows a popup.
What code should show a popup?
see server-response-display.component.html
that is the popup code
the app,component.ts file automatically calles the InternetCheck service
Like that the pop up is shown
Sorry I do not understand how a popup should be shown.
Where is server response display rendered ?
go to app,component.ts
do you see constructor(private readonly internetCheckService: InternetCheckService) {}
from there the service is called
in app.component.html
its not
<div class="app-container">
<h1>Internet Check</h1>
</div>
thats the html I see.
yeah it activates in app.,component.ts and render in app.component.html
The code for showing a popup is not used.
if there is no internet in app.component.html, it will display the popup
No.
but it works for me
It does not work in stackblitz.
locally
Because of what I said.
The code that shows the popup is never called, because its not part of app component.
So if u ask why a popup isnt shown, it's because you never try and show one on the stackblitz.
but why is it working locally?
im using the same code as stackblitz locally, but the popup is coming then
yeah i saved
What sthe link ?
yeah that is what i see too
when it is running the InternetCheck service inside app.component.ts
There is no code in app.component.ts to display a popup.
without any code , the app is displaying the popup bro
@wheat tangle I have updated the code could you check now
link?
I have imported
import { ServerResponseDisplayComponent } from 'src/ui/server-response-display/server-response-display.component';
Could you check now
Does it work for you on stackblitz ?
I told you there is no output coming for me in stackblitz
I dont know why
I tried refreshing too
Maybe u should solve that.
Its full of errors
'app-general-dialogue' is not a known element:
Ensure the stackblitz is running and I am happy to help you. But this is not a very useful way to use my time.
Hey, my stackblitz is running now
But im not able to solve thsis error
'app-server-response-display' is not a known element:
Yeah u need to fix that.
I tried importing the component to app.component.ts file
Whats the link ?
Where did u try and import the component ?
the route to ServerResponseDisplayComponent is correct but still module not found error is coming
to app.component.ts
That's not what you should do.
Then?
I'm sorry, it does look like you should take a step back and try and understand what we are doing.
In order to use a component, u dont just import {SomeComponent} from 'path'.
I only declared it in the module
Where are you importing that module?
in app.module.ts
And where is ServerModule?
in server-response-display folder
Please refresh and check?
Ah I see it now.
Still why is it showing that error
Your code is full of errors.
where are these errors shown?
Im only seeing this
can i give you git repo?
@wheat tangle
'app-general-dialogue' is not a known element:
I recommend you to take a step back and familiarize with Angular. I had to fix a lot of things to get to that error.
could you share the updated link of stackblitz
okay
I'm pointing to the correct file but still its saying module not found
import { GeneralDialogueModule } from 'src/ui/general-dialogue/general-dialogue.module';
Cannot find module 'src/ui/general-dialogue/general-dialogue.module' or its corresponding type declarations.
@wheat tangle
I would advise you to take a step back and understand what's happening. I cant keep fixing all these copy paste issues.
Also use relative paths
Look at other import paths i added.
I don't know what I'm doing wrong. I'm really confused why the path is giving me an error. @wheat tangle
Use a relative path
import { GeneralDialogueModule } from '../ui/general-dialogue/general-dialogue.module';
like this right?
../..
Then u get
The class 'GeneralDialogueModule' is listed in the declarations of the NgModule 'ServerModule', but is not a directive, a component, or a pipe. Either remove it from the NgModule's declarations, or add an appropriate Angular decorator.
Which is all copy paste errors that I cant keep fixing for you, sorry.
Same with the relative paths.
Ping me when the SB works, and I am happy to look at it.
Here is the internet check popup which comes when the internet is not there. When I click the try again button, it should call the internet check function again
Here is the repo - https://github.com/Adarsh88/internet-check
@wheat tangle
Where can I find the code that reacts to clicking retry @reef raven ?
Its on services -> internet-check.service.ts. It's this line
this.serverResponseDisplayService.messageDisplaySubscribableFromPopUp
.pipe(take(1))
.subscribe((data) => {
if (data === 'retry') {
// call internet function again to check if internet connection is there or not
}
});
@wheat tangle
And what component do u want to rexecute ?
I mean, based on the comment you want to call a method inside the same service
which isnt what you initially mentioned.
Do u want to keep showing a retry popup until there is internet?
That is nowhere close to what you have been asking for days.
I was mentioning that issue only
Look at the threads title ... "How to access a components function in service".
Actually I wanted to access ngOnInit
of app.component.ts
but then got to know that I want to access the constructor
@reef raven Im not even getting a popup on your repo?
Anyway, this works for me:
export class InternetCheckService {
isConnectedToInternet = true;
constructor(
private connectionService: ConnectionService,
private serverResponseDisplayService: ServerResponseDisplayService
) {
this.connectionService.monitor().pipe(
delay(500),
take(1),
mergeMap((connectionState) =>
connectionState.hasInternetAccess
? of(false)
: this.displayNoInternetMessage()
),
filter(retry => !!retry),
repeat()
).subscribe(console.log);
}
displayNoInternetMessage() {
this.serverResponseDisplayService.errorMessageToShow({
title: 'No internet connection.',
buttonText: 'Close',
message: 'Please try again later or try refreshing the page.',
});
return this.serverResponseDisplayService.messageDisplaySubscribableFromPopUp.pipe(
take(1),
map((data) => data === 'retry')
);
}
}
You do want to get rid of the delay.
I'm getting the popup
Ah yeah, makes sense.
Let me try something else first.
Okay
Whats the point of the retry function tho?
As monitor will keep monitoring untill internet is back ?
there is no real retry.
I think it would be better to show a popup saying NO INTERNET
without retry
and wait untill monitor shows u have internet again
and close it
No i have to keep the try again button on the project
Can we make the try again functionality work?
So when u show a popup, you want to wait for manual retry, even if internet is back sooner?
Yeah
Uff, okay. That might be complicated.
If internet is back sooner, then the popup could be closed
I dont think the library u use is designed for what you try to do.
it's used to monitor for internet connection, not for manual checking if there is internet connection.
I dont want to manual check
I just want to check whether there is internet is there or not, while clicking on retry button
If there is not the popup should again appear
or else it should not appear
clickin retry is a manual check.
which the library does not support.
The librarry checks automatically every 3 seconds.
Basically using repeat()
i have to try out this code right? @wheat tangle
It's a good start, but not the final solution as I believe the library you have doesnt realy do what you want to do.
I tried that code but when the wifi is turned on, still the popup is getting displayed over and over again
@wheat tangle Any idea why?
Well the library does not allow to do what you want
It takes 3 seconds before it picks up the connection
Thats okay for me
I just want to close or not show the popup when there is internet @wheat tangle
Do you already have the ability to close the popup?
No when I click the close button, it reloads the popup
Track the open popup, and close it when monitor emits true
Any way to do this? @wheat tangle
No I wasnt able to track it
What have you tried ?
When the internet is turned on, I tried to make the popup disappear. But could not do that
Still the popup is coming again and again
Are you able to track the popup @wheat tangle
What library do u use to open the popup
It uses the server error display service that opens the popup
Try using an existing solution, it allows to close popups most of the time.
What type of solution are you talking about
UI component infrastructure and Material Design components for Angular web applications.
Bootstrap 5 and Bootstrap 4 widgets for Angular: accordion, alerts, buttons, carousel, collapse, datepicker, dropdowns, modals, pagination, popover, progressbar, rating, sortable, tabs, timepicker, tooltip, typeahead
@wheat tangle I was able to close the popup. But when I close it, it does not reappear when internet it turned off
I used this on the server error display component
(click)="modalRef?.hide()">
Honestly, I have no idea what you are trying anymore. i thought u wanted to closwe it when internet is back, not when u click somewhere.
Yeah no idea man. That used to work before, so I have no idea what changed.
But as much as I want to help u, I think its better to not ping me 50 times per day
Update your github project, share it and be very clear in what you want.
There are alot of people thet can help you, not just me.
Apparently the connection state's hasInternetAccess was not working properly. When I changed it to hasNetworkConnection, everything works fine. Thanks so much for patiently making me understand where I'm going wrong and rectifying my errors. @wheat tangle
Hey @wheat tangle, I wanted to automatically close the popup when there is internet. So I modified your code like this, but it is giving me this error - Type '(() => void) | Observable<boolean>' is not assignable to type 'ObservableInput<any>'. Here is the modified code. Any idea why I'm not able to call that function?
import {Injectable} from '@angular/core';
import {ConnectionService} from 'ng-connection-service';
import {ModalPopupService} from '../../components/ui/modal-popup/service/modal-popup.service';
import {ServerResponseDisplayService} from '@components/ui/server-response-display/server-response-display-service/server-response-display.service';
import {take, delay, of} from 'rxjs';
import {mergeMap, repeat, map} from 'rxjs/operators';
@Injectable({
providedIn: 'root',
})
export class NetworkCheckService {
isConnectedToInternet = true;
constructor(
private connectionService: ConnectionService,
private serverResponseDisplayService: ServerResponseDisplayService,
private modalPopup: ModalPopupService
) {
this.connectionService
.monitor()
.pipe(
delay(500),
take(1),
mergeMap(connectionState =>
connectionState.hasNetworkConnection
? this.popUpCloseHandler
: this.displayNoInternetMessage()
),
repeat()
)
.subscribe();
}
displayNoInternetMessage() {
this.serverResponseDisplayService.errorMessageToShow({
title: 'No internet connection.',
buttonText: 'Close',
message: 'Please try again later or try refreshing the page.',
});
return this.serverResponseDisplayService.messageDisplaySubscribableFromPopUp.pipe(
take(1),
map(data => data === 'retry')
);
}
popUpCloseHandler() {
this.modalPopup.close('error-popup');
}
}
The issue is with popupCloseHandler inside mergeMap
You need to add ()
As well as return an observable
You can use tap if u don't want to return an observable.
But if u use mergeMap u need to return an observable.
is there any way other than mergeMap to use the ternary operation
The second part returns an observable
So yeah mixing those two in a single ternary is gonna be a bit weird.
Oh okay
So how can I return this as a observable
popUpCloseHandler() {
this.modalPopup.close('error-popup');
}
I figured out a way @wheat tangle . But still, the popup is not getting automatically closed when I turn on the internet.
import {Injectable} from '@angular/core';
import {ConnectionService} from 'ng-connection-service';
import {ModalPopupService} from '../../components/ui/modal-popup/service/modal-popup.service';
import {ServerResponseDisplayService} from '@components/ui/server-response-display/server-response-display-service/server-response-display.service';
import {take, delay, of} from 'rxjs';
import {mergeMap, repeat, map} from 'rxjs/operators';
import {Observable} from 'rxjs';
@Injectable({
providedIn: 'root',
})
export class NetworkCheckService {
isConnectedToInternet = true;
constructor(
private connectionService: ConnectionService,
private serverResponseDisplayService: ServerResponseDisplayService,
private modalPopup: ModalPopupService
) {
this.connectionService
.monitor()
.pipe(
delay(500),
take(1),
mergeMap(connectionState =>
connectionState.hasNetworkConnection
? this.popUpCloseHandler()
: this.displayNoInternetMessage()
),
repeat()
)
.subscribe();
}
displayNoInternetMessage() {
this.serverResponseDisplayService.errorMessageToShow({
title: 'No internet connection.',
buttonText: 'Close',
message: 'Please try again later or try refreshing the page.',
});
return this.serverResponseDisplayService.messageDisplaySubscribableFromPopUp.pipe(
take(1),
map(data => data === 'retry')
);
}
popUpCloseHandler(): Observable<boolean> {
return new Observable(observer => {
this.serverResponseDisplayService.messageDisplayFromPopUp.next('custom');
observer.next(true);
observer.complete();
});
}
}
Yeah I'd think so.
Yeah I did that, still does not work. Any other way @wheat tangle
I have no idea what doesnt work.
As mentioned before, I encourage you to use something that already exists to handle popups.
Here is the console log
I found out something
When the internet is turned off
The internet check gives false and then never checks again
Until the close button is click
With the take(1)?
Yeah with the take(1)
Sounds expected.
I think it's because mergeMap checks the internet check only when connectionState hasNetworkConnection
take 1 means ... only take 1.