A library for loading spinner for Angular 4 - 17.
A library with more than 50 different loading spinners for Angular 4 - 17. (https://napster2210.github.io/ngx-spinner/)
Use appropriate version based on your Angular version.
Angular 17 | Angular 16 | Angular 15 |
---|---|---|
>=v17.0.0 |
>=v16.0.2 |
>=v15.0.1 |
Angular 14 | Angular 13 | Angular 12 | Angular 11 | Angular 10 |
---|---|---|---|---|
>=v14.0.0 |
>=v13.1.1 |
>=v12.0.0 |
>=v11.0.2 |
>=v10.0.1 |
Angular 9 | Angular 8 | Angular 6/7 | Angular 5 | Angular 4 |
---|---|---|---|---|
>=v9.0.1 |
v8.1.0 |
v7.2.0 |
>=v1.2.0 |
>=v2.0.0 |
Chrome | Firefox | IE / Edge | Safari | Opera |
---|---|---|---|---|
Latest ✔ | Latest ✔ | IE11, Edge ✔ | Latest ✔ | Latest ✔ |
img
tagshow()/hide()
methods return promisez-index
hide/show
the spinnerngx-spinner
is available via npm and yarn
Using npm:
$ npm install ngx-spinner --save
Using yarn:
$ yarn add ngx-spinner
Using angular-cli:
$ ng add ngx-spinner
Add css animation files to angular.json config
{
"styles": [
"node_modules/ngx-spinner/animations/ball-scale-multiple.css" // ===> Add css file based on your animation name(here it's "ball-scale-multiple")
// You're able to add multiple files if you need
]
}
Import NgxSpinnerModule
in in the root module(AppModule
):
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
// Import library module
import { NgxSpinnerModule } from "ngx-spinner";
@NgModule({
imports: [
// ...
BrowserAnimationsModule,
NgxSpinnerModule,
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class AppModule {}
forRoot
method for NgxSpinnerModule and pass configuration object.// Available options
interface NgxSpinnerConfig {
type?: string;
}
// Use in app
@NgModule({
imports: [
NgxSpinnerModule.forRoot({ type: 'ball-scale-multiple' })
]
})
Add NgxSpinnerService
service wherever you want to use the ngx-spinner
.
import { NgxSpinnerService } from "ngx-spinner";
class AppComponent implements OnInit {
constructor(private spinner: NgxSpinnerService) {}
ngOnInit() {
/** spinner starts on init */
this.spinner.show();
setTimeout(() => {
/** spinner ends after 5 seconds */
this.spinner.hide();
}, 5000);
}
}
Now use in your template
<ngx-spinner type="ball-scale-multiple"></ngx-spinner>
See Demo
NgxSpinnerService.show()
Shows the spinnerNgxSpinnerService.hide()
Hides the spinnerrgba(51,51,51,0.8)
where alpha
value(0.8) is opacity of backdropsmall
, default
, medium
, large
.large
#fff
true
or false
true
primary
99999
null
true
or false
true
or false
false
<ngx-spinner
bdColor="rgba(51,51,51,0.8)"
size="medium"
color="#fff"
type="ball-scale-multiple"
>
<p style="font-size: 20px; color: white">Loading...</p>
</ngx-spinner>
<ngx-spinner
bdColor="rgba(0, 0, 0, 1)"
template="<img src='https://media.giphy.com/media/o8igknyuKs6aY/giphy.gif' />"
>
</ngx-spinner>
HTML
code as loading text now, instead of input parameter(loadingText
). Check above code for reference.ngx-spinner
instance, just add name
attribute with ngx-spinner
component. But in this case, you’ve to pass that particular name of a spinner in show/hide
method. Check Demoangular.json
filethis.spinner.show("mySpinner", {
type: "line-scale-party",
size: "large",
bdColor: "rgba(0, 0, 0, 1)",
color: "white",
template:
"<img src='https://media.giphy.com/media/o8igknyuKs6aY/giphy.gif' />",
});
type
will be ball-8bits
.ball-8bits
animation(e.g. ball-8bits.css
)CUSTOM_ELEMENTS_SCHEMA
as your schema in your main module.show()
methods in a single component or single function one after another then wrap the show()
method within setTimeout()
method to avoid any rendering issue.fullScreen: false
), in that case your parent element of spinner must have position: relative;
style property.ngx-spinner will be maintained under the Semantic Versioning guidelines.
Releases will be numbered with the following format:
<major>.<minor>.<patch>
For more information on SemVer, please visit http://semver.org.
Inspired by Load Awesome by Daniel Cardoso.
Thanks Alex Vieira Alencar for helping me with Multiple Spinner Support.
Thanks ennjin for reducing the bundle size.
ngx-spinner is MIT licensed.