Simple & lightweight Angular 2/4 voting component. Demo is available on Plunker.
To install ng-vote, run:
$ npm install ng-vote --save
Import NgVoteModule
into your Angular application:
// Import ng-vote
import { NgVoteModule } from 'ng-vote';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
// Specify ng-vote as an import
NgVoteModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Once ng-vote is imported, you can use it in your Angular application:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
voteConfig: {
cssClass: 'my-class',
allowEdit: true,
disabled: false
}
votes: 123, // total amount of votes
selectedVote: 0 // not voted yet
onVote(vote) {
console.log('onVote response: ', vote)
}
}
<!-- You can now use ng-vote component in your application -->
<ng-vote
(vote)="onVote($event)"
[totalVotes]="votes"
[selectedVote]="selectedVote"
[config]="voteConfig">
<!-- Define Up Vote Button -->
<ng-vote-up>
<!-- Content will be projected -->
<i class="my-up-icon"></i>Up
</ng-vote-up>
<!-- Add Down Vote Button -->
<ng-vote-down>Down</ng-vote-down>
</ng-vote>
<!-- Minimal setup would be -->
<ng-vote (vote)="onVote($event)">
<ng-vote-up>Up</ng-vote-up>
<ng-vote-down>Down</ng-vote-down>
</ng-vote>
- [totalVotes]: number
Default: 0
- [selectedVote]: number
Default: 0
One of -1 (downVote), 0 (not voted), 1 (upVote) - [config]: Object
- allowEdit: boolean
Default: true
Defines if user is allowed to change his the selection. - disabled: boolean
Default: false
Disables vote functionality. - cssClass: string
Default: ''
Sets custom css class to override styles.
- allowEdit: boolean
- (vote): Object
- selectedVote: number
- totalVotes: number
No bindings available for <ng-vote-up>
/ <ng-vote-down>
. Content will be projected to the <button>
.
Demo of the Angular 2/4 voting component is available on Plunker.
The MIT License (MIT)
Copyright (c) 2017 Patrick Valer
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Made with โฅ by Patrick Valer (hello@patrickvaler.ch)