Angular: Showing loading bar in a component when changing route@Directive v/s @Component in AngularHow to detect a route change in Angular?Angular - Use pipes in services and componentsAngular2 Navigation using Arrow KeysAngular/RxJs When should I unsubscribe from `Subscription`How to detect when an @Input() value changes in Angular?Angular2: how to set component to show after ajax loading of data?Loading components as soon as possibleAngular 4 LazyLoad child routes fails when child has same pathShow loading indicator in Angular while waiting for a RxJS observable
Have astronauts in space suits ever taken selfies? If so, how?
Approximately how much travel time was saved by the opening of the Suez Canal in 1869?
What are the differences between the usage of 'it' and 'they'?
Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?
Can I ask the recruiters in my resume to put the reason why I am rejected?
can i play a electric guitar through a bass amp?
Today is the Center
Why are 150k or 200k jobs considered good when there are 300k+ births a month?
How can I make my BBEG immortal short of making them a Lich or Vampire?
Dragon forelimb placement
How did the USSR manage to innovate in an environment characterized by government censorship and high bureaucracy?
How much RAM could one put in a typical 80386 setup?
Python: next in for loop
What is the offset in a seaplane's hull?
Writing rule which states that two causes for the same superpower is bad writing
How is it possible to have an ability score that is less than 3?
Is it possible to rebuild the bike frame (to make it lighter) by welding aluminum tubes
How does one intimidate enemies without having the capacity for violence?
Why do falling prices hurt debtors?
Is it possible to do 50 km distance without any previous training?
A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?
What defenses are there against being summoned by the Gate spell?
Can I make popcorn with any corn?
How to say job offer in Mandarin/Cantonese?
Angular: Showing loading bar in a component when changing route
@Directive v/s @Component in AngularHow to detect a route change in Angular?Angular - Use pipes in services and componentsAngular2 Navigation using Arrow KeysAngular/RxJs When should I unsubscribe from `Subscription`How to detect when an @Input() value changes in Angular?Angular2: how to set component to show after ajax loading of data?Loading components as soon as possibleAngular 4 LazyLoad child routes fails when child has same pathShow loading indicator in Angular while waiting for a RxJS observable
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
Not sure what is the best approach to achieve this.
I have a list of items at this URL: http://localhost/items
When user clicks the edit button(let's say the item 2 button) it will change the route to http://localhost/items/item2
Now I want to get information from database for the selected item and show details information. While waiting for data from the server I want to show a loading progress where the items list is placed, while showing the menu and info components. Like this:
One approach that I used to do this was to simply load the ItemDetails
component , show the loading label, made a request to get details and when the data is received I hide the loading label.
ngOnInit()
this.loading = true;
const itemID = this.route.snapshot.paramMap.get('id');
this.itemsService
.getItem(itemID)
.subscribe(restult =>
//process result
this.loading = false;
);
This approach works great but I'm not sure if this is an anti-pattern or not.
The second approach I tried was using a resolver to get the item info and rely on router events(NavigationStart
, NavigationEnd
) to show the loading label.
The problem with this approach is when the user enters the item details URL in the browser( doesn't click the edit button) : http://localhost/items/item2
. it will wait until the data is received then will render all components(menu,info and of course the item details).
So, it is OK to use the first approach or is it an anti pattern? If it's an anti pattern what's the best way to resolve this using a resolver or any other approach in a way that I'm able to show some components(menu,loading bar) while retrieving the data?
angular angular-router
add a comment |
Not sure what is the best approach to achieve this.
I have a list of items at this URL: http://localhost/items
When user clicks the edit button(let's say the item 2 button) it will change the route to http://localhost/items/item2
Now I want to get information from database for the selected item and show details information. While waiting for data from the server I want to show a loading progress where the items list is placed, while showing the menu and info components. Like this:
One approach that I used to do this was to simply load the ItemDetails
component , show the loading label, made a request to get details and when the data is received I hide the loading label.
ngOnInit()
this.loading = true;
const itemID = this.route.snapshot.paramMap.get('id');
this.itemsService
.getItem(itemID)
.subscribe(restult =>
//process result
this.loading = false;
);
This approach works great but I'm not sure if this is an anti-pattern or not.
The second approach I tried was using a resolver to get the item info and rely on router events(NavigationStart
, NavigationEnd
) to show the loading label.
The problem with this approach is when the user enters the item details URL in the browser( doesn't click the edit button) : http://localhost/items/item2
. it will wait until the data is received then will render all components(menu,info and of course the item details).
So, it is OK to use the first approach or is it an anti pattern? If it's an anti pattern what's the best way to resolve this using a resolver or any other approach in a way that I'm able to show some components(menu,loading bar) while retrieving the data?
angular angular-router
I think your approach is fine. Are you using SSR (Server-side rendering) or client-side rendering? Why im asking this, because if you control over your browser or page load event for first start, you can fire loading = true so control over your URL is the browser enters.
– shadowman_93
Mar 9 at 7:46
add a comment |
Not sure what is the best approach to achieve this.
I have a list of items at this URL: http://localhost/items
When user clicks the edit button(let's say the item 2 button) it will change the route to http://localhost/items/item2
Now I want to get information from database for the selected item and show details information. While waiting for data from the server I want to show a loading progress where the items list is placed, while showing the menu and info components. Like this:
One approach that I used to do this was to simply load the ItemDetails
component , show the loading label, made a request to get details and when the data is received I hide the loading label.
ngOnInit()
this.loading = true;
const itemID = this.route.snapshot.paramMap.get('id');
this.itemsService
.getItem(itemID)
.subscribe(restult =>
//process result
this.loading = false;
);
This approach works great but I'm not sure if this is an anti-pattern or not.
The second approach I tried was using a resolver to get the item info and rely on router events(NavigationStart
, NavigationEnd
) to show the loading label.
The problem with this approach is when the user enters the item details URL in the browser( doesn't click the edit button) : http://localhost/items/item2
. it will wait until the data is received then will render all components(menu,info and of course the item details).
So, it is OK to use the first approach or is it an anti pattern? If it's an anti pattern what's the best way to resolve this using a resolver or any other approach in a way that I'm able to show some components(menu,loading bar) while retrieving the data?
angular angular-router
Not sure what is the best approach to achieve this.
I have a list of items at this URL: http://localhost/items
When user clicks the edit button(let's say the item 2 button) it will change the route to http://localhost/items/item2
Now I want to get information from database for the selected item and show details information. While waiting for data from the server I want to show a loading progress where the items list is placed, while showing the menu and info components. Like this:
One approach that I used to do this was to simply load the ItemDetails
component , show the loading label, made a request to get details and when the data is received I hide the loading label.
ngOnInit()
this.loading = true;
const itemID = this.route.snapshot.paramMap.get('id');
this.itemsService
.getItem(itemID)
.subscribe(restult =>
//process result
this.loading = false;
);
This approach works great but I'm not sure if this is an anti-pattern or not.
The second approach I tried was using a resolver to get the item info and rely on router events(NavigationStart
, NavigationEnd
) to show the loading label.
The problem with this approach is when the user enters the item details URL in the browser( doesn't click the edit button) : http://localhost/items/item2
. it will wait until the data is received then will render all components(menu,info and of course the item details).
So, it is OK to use the first approach or is it an anti pattern? If it's an anti pattern what's the best way to resolve this using a resolver or any other approach in a way that I'm able to show some components(menu,loading bar) while retrieving the data?
angular angular-router
angular angular-router
asked Mar 9 at 2:56
Doua BeriDoua Beri
3,946125699
3,946125699
I think your approach is fine. Are you using SSR (Server-side rendering) or client-side rendering? Why im asking this, because if you control over your browser or page load event for first start, you can fire loading = true so control over your URL is the browser enters.
– shadowman_93
Mar 9 at 7:46
add a comment |
I think your approach is fine. Are you using SSR (Server-side rendering) or client-side rendering? Why im asking this, because if you control over your browser or page load event for first start, you can fire loading = true so control over your URL is the browser enters.
– shadowman_93
Mar 9 at 7:46
I think your approach is fine. Are you using SSR (Server-side rendering) or client-side rendering? Why im asking this, because if you control over your browser or page load event for first start, you can fire loading = true so control over your URL is the browser enters.
– shadowman_93
Mar 9 at 7:46
I think your approach is fine. Are you using SSR (Server-side rendering) or client-side rendering? Why im asking this, because if you control over your browser or page load event for first start, you can fire loading = true so control over your URL is the browser enters.
– shadowman_93
Mar 9 at 7:46
add a comment |
1 Answer
1
active
oldest
votes
You can also use the npm package for the same, So you don't need to set loading flag for each request here is the npm package example.
Package: https://www.npmjs.com/package/ng-http-loader
$ npm install ng-http-loader --save / yarn add ng-http-loader
In AppModule:
`import BrowserModule from '@angular/platform-browser';
import NgModule from '@angular/core';
import AppComponent from './app.component';
import HttpClientModule from '@angular/common/http';
import NgHttpLoaderModule from 'ng-http-loader';
@NgModule(
declarations: [
AppComponent
],
imports: [
BrowserModule,
HttpClientModule, // <============ (Perform HTTP requests with this module)
NgHttpLoaderModule.forRoot(), // <============ Don't forget to call 'forRoot()'!
],
providers: [],
bootstrap: [AppComponent]
)
export class AppModule `
In app.component.html
<ng-http-loader></ng-http-loader>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073574%2fangular-showing-loading-bar-in-a-component-when-changing-route%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can also use the npm package for the same, So you don't need to set loading flag for each request here is the npm package example.
Package: https://www.npmjs.com/package/ng-http-loader
$ npm install ng-http-loader --save / yarn add ng-http-loader
In AppModule:
`import BrowserModule from '@angular/platform-browser';
import NgModule from '@angular/core';
import AppComponent from './app.component';
import HttpClientModule from '@angular/common/http';
import NgHttpLoaderModule from 'ng-http-loader';
@NgModule(
declarations: [
AppComponent
],
imports: [
BrowserModule,
HttpClientModule, // <============ (Perform HTTP requests with this module)
NgHttpLoaderModule.forRoot(), // <============ Don't forget to call 'forRoot()'!
],
providers: [],
bootstrap: [AppComponent]
)
export class AppModule `
In app.component.html
<ng-http-loader></ng-http-loader>
add a comment |
You can also use the npm package for the same, So you don't need to set loading flag for each request here is the npm package example.
Package: https://www.npmjs.com/package/ng-http-loader
$ npm install ng-http-loader --save / yarn add ng-http-loader
In AppModule:
`import BrowserModule from '@angular/platform-browser';
import NgModule from '@angular/core';
import AppComponent from './app.component';
import HttpClientModule from '@angular/common/http';
import NgHttpLoaderModule from 'ng-http-loader';
@NgModule(
declarations: [
AppComponent
],
imports: [
BrowserModule,
HttpClientModule, // <============ (Perform HTTP requests with this module)
NgHttpLoaderModule.forRoot(), // <============ Don't forget to call 'forRoot()'!
],
providers: [],
bootstrap: [AppComponent]
)
export class AppModule `
In app.component.html
<ng-http-loader></ng-http-loader>
add a comment |
You can also use the npm package for the same, So you don't need to set loading flag for each request here is the npm package example.
Package: https://www.npmjs.com/package/ng-http-loader
$ npm install ng-http-loader --save / yarn add ng-http-loader
In AppModule:
`import BrowserModule from '@angular/platform-browser';
import NgModule from '@angular/core';
import AppComponent from './app.component';
import HttpClientModule from '@angular/common/http';
import NgHttpLoaderModule from 'ng-http-loader';
@NgModule(
declarations: [
AppComponent
],
imports: [
BrowserModule,
HttpClientModule, // <============ (Perform HTTP requests with this module)
NgHttpLoaderModule.forRoot(), // <============ Don't forget to call 'forRoot()'!
],
providers: [],
bootstrap: [AppComponent]
)
export class AppModule `
In app.component.html
<ng-http-loader></ng-http-loader>
You can also use the npm package for the same, So you don't need to set loading flag for each request here is the npm package example.
Package: https://www.npmjs.com/package/ng-http-loader
$ npm install ng-http-loader --save / yarn add ng-http-loader
In AppModule:
`import BrowserModule from '@angular/platform-browser';
import NgModule from '@angular/core';
import AppComponent from './app.component';
import HttpClientModule from '@angular/common/http';
import NgHttpLoaderModule from 'ng-http-loader';
@NgModule(
declarations: [
AppComponent
],
imports: [
BrowserModule,
HttpClientModule, // <============ (Perform HTTP requests with this module)
NgHttpLoaderModule.forRoot(), // <============ Don't forget to call 'forRoot()'!
],
providers: [],
bootstrap: [AppComponent]
)
export class AppModule `
In app.component.html
<ng-http-loader></ng-http-loader>
answered Mar 9 at 3:51
Yash RamiYash Rami
40137
40137
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073574%2fangular-showing-loading-bar-in-a-component-when-changing-route%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I think your approach is fine. Are you using SSR (Server-side rendering) or client-side rendering? Why im asking this, because if you control over your browser or page load event for first start, you can fire loading = true so control over your URL is the browser enters.
– shadowman_93
Mar 9 at 7:46