Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@chevtek/angular-spinners
Advanced tools
A library for easily managing loading spinners in complex Angular2+ applications.
NOTICE
@chevtek/angular-spinners
v5 or higher is now for Angular 2 or higher. If you are looking to install the old version for AngularJS 1.x you may runnpm install angular-spinners@3.1.2
. Note the lack of@chevtek/
in front of the package name. The older versions of this package were not published under the Chevtek scope. That version is considered deprecated and is no longer supported unless I find a major issue, but feel free to continue using it as it has proven to be quite reliable in AngularJS 1.x. You will never see changes to the old version of angular-spinners except in the case of potential patch versions (3.1.x) if anything major gets reported for the old version.
$ npm i angular-spinners --save
If you're running npm v8 or higher then --save
is implied if you don't include it.
import { SpinnerModule } from 'angular-spinners';
@NgModule({
imports: [
BrowserModule,
SpinnerModule,
...
]
...
})
export class AppModule { }
Next simply drop a spinner directive in your app. The only required attribute is name
.
<spinner name="mySpinner"></spinner>
Now just inject the SpinnerService
wherever you need it.
import { SpinnerService } from 'angular-spinners';
@Injectable()
export class YourService {
public constructor(protected spinnerService: SpinnerService) {}
beginSomeOperation(): void {
this.spinnerService.show('mySpinner');
this.doSomething().then(() => {
this.spinnerService.hide('mySpinner');
});
}
}
Here is a working demo.
The spinner component gives you several options.
The name attribute is required. It is what you must pass to the service when trying to show/hide that specific spinner.
<spinner name="mySpinner"></spinner>
Optionally a group name may be specified so that you can show/hide groups of spinners.
<spinner name="mySpinner" group="foo"></spinner>
<spinner name="mySpinner2" group="foo"></spinner>
<spinner name="mySpinner3" group="bar"></spinner>
@Injectable()
export class YourService implements OnInit {
constructor(private spinnerService: SpinnerService) { }
ngOnInit(): void {
this.spinnerService.showGroup('foo');
}
}
Both name
and group
are input parameters you can bind to if needed.
<spinner [name]="dynamicSpinnerName" [group]="dynamicGroupName"></spinner>
By default all spinners are hidden when first registered. You can set a spinner to be visible by default by setting the show
property to true
.
<spinner name="mySpinner" [show]="true"></spinner>
Note: Don't forget to bind to the show
parameter if you plan to pass the literal value true
. If you try doing show="true"
instead of [show]="true"
you'll be passing the string value "true"
rather than the boolean value of true
.
You can even two-way bind to the show
property giving you full control over how you show/hide your spinner and what side effects that has in your app.
Example:
@Component({
selector: 'my-component',
template: `
<spinner name="mySpinner" [(show)]="spinnerShowing"></spinner>
<button (click)="spinnerShowing = !spinnerShowing">
{{spinnerShowing ? 'Hide' : 'Show'}} Spinner
</button>
`
})
export class MyComponent {
spinnerShowing: boolean = false;
}
Two-way binding allows changes to show
to be propagated back to your app allowing you to still use the SpinnerService
API in conjunction with your own logic and everything will stay in sync.
Passing in a loading image is the simplest way to create a quick spinner.
<spinner name="mySpinner" loadingImage="/path/to/loading.gif"></spinner>
If you want to disable the loading image entirely then simply do not specify the loadingImage
property and an image won't be used. If you don't include the loadingImage
option then be sure to specify some custom markup within the spinner directive itself so it can be used instead.
If you need more control over the kind of spinner you want to display, beyond just a simple animated image. You are able to supply any custom markup that you need by simply nesting it within the spinner directive. Any content will be projeced into the spinner template below the loadingImage
if one was specified.
<spinner name="mySpinner">
<h3>Loading...</h3>
</spinner>
Content projection is the most common way to use the SpinnerComponent
as it allows you to pass in custom markup and use CSS animations instead of an animated .gif image.
The most common way of interacting with your spinners is via the spinnerService
. This service can be injected just like any other Angular service. Once you have reference to the service you can take advantage of several methods.
import { SpinnerService } from 'angular-spinners';
@Injectable()
export class YourService {
constructor(
private spinnerService: SpinnerService,
private http: Http
) {}
loadData(): void {
this.spinnerService.show('mySpinner');
this.http
.get('/some/url/for/data/')
.toPromise()
then(res => {
this.spinnerService.hide('mySpinner');
// do stuff with res
})
.catch(err => {
this.spinnerService.hide('mySpinner');
// log error
})
}
}
The show
method allows you to display a specific spinner by name.
<spinner name="mySpinner" loadingImage="/path/to/loader.gif"></spinner>
spinnerService.show('mySpinner');
Works exactly like show
but hides the spinner element.
The showGroup
method allows you to display all spinners with the same group name.
<spinner name="spinner1" group="foo"></spinner>
<spinner name="spinner2" group="foo"></spinner>
<spinner name="spinner3" group="bar"></spinner>
spinnerService.showGroup('foo');
Spinners 1 and 2 would show but spinner 3 would not since it is not part of group "foo".
Works exactly the same as showGroup
except it hides the spinners instead.
Hopefully it's obvious that this method will show every single spinner registered with the service. This method is rarely used but is there for parity just in case.
The hideAll
method is identical to showAll
except it hides every spinner that is registered. This method also isn't used very often but is extremely useful in global error handlers. We all know how much users HATE frozen spinners, right?
The isShowing
method returns a boolean indicating whether or not the specified spinner is currently showing. You can already two-way bind to the show
property on the component but rarely you may want to get this information in a distant part of your app without having to manually wire your app to expose it.
FAQs
Easy loading spinner management for apps running Angular 2+
The npm package @chevtek/angular-spinners receives a total of 33 weekly downloads. As such, @chevtek/angular-spinners popularity was classified as not popular.
We found that @chevtek/angular-spinners demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.