@SannNL wrote:
Hello, I'm trying to refactor this because I think it can be cleaner but I'm not sure how. It's about the 'notification' object.
I have this provider, which defines the possible notifications (/errors):
import {Injectable} from '@angular/core'; @Injectable() export class GlobalProvider { notification: object; constructor() { this.notification = { internal: { image: 'assets/img/interne-fout.svg', title: 'Er is een interne fout', content: 'Probeer het opnieuw, als het probleem aanhoudt neem contact op' }, internet: { image: 'assets/img/geen-data.svg', title: 'Je hebt geen verbinding', content: 'Check je internetconnectie en probeer het nogmaals' } }; } isOnline() { return navigator.onLine; } }
In my component I have this.
notification: object = {image: '', title: '', content: ''}; /** * Only do request when online. */ if (globalProvider.isOnline()) { this.sendHTTPRequest(); } else { this.notification = globalProvider.notification['internet']; } /** * Watch for reconnect after disconnect. */ this.network.onConnect().subscribe(() => { this.sendHTTPRequest(); this.notification = {image: '', title: '', content: ''}; });
Is there any better way to do this? I don't like the redefining the structure of notification in the component part. Feels wrong somehow.
Posts: 1
Participants: 1