
Security News
The Code You Didn't Write Is Still Yours to Defend
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.
angular2-swing
Advanced tools
npm install angular2-swing --save
import {Component, ViewChild, ViewChildren, QueryList} from '@angular/core';
import {
StackConfig,
Stack,
Card,
ThrowEvent,
DragEvent,
SwingStackComponent,
SwingCardComponent} from 'angular2-swing';
@Component({
selector: 'app',
directives: [SwingStackComponent, SwingCardComponent],
template: `
<div id="viewport">
<ul class="stack" swing-stack [stackConfig]="stackConfig" #myswing1 (throwout)="onThrowOut($event)">
<li swing-card #mycards1 [ngClass]="c.name" *ngFor="let c of cards">{{ c.symbol }}</li>
</ul>
</div>
<div id="source">
<p>Drag the playing cards out of the stack and let go. Dragging them
beyond the desk will throw them out of the stack. If you drag too
little and let go, the cards will spring back into place. You can
throw cards back into the stack after you have thrown them out.</p>
<p>Open the <a href="https://developer.chrome.com/devtools/docs/console">
Console</a> to view the associated events.<p>
<p>Demonstration of <a href="https://github.com/ksachdeva/angular2-swing">
https://github.com/ksachdeva/angular2-swing</a> implementation.</p>
</div>
`
})
export class App {
@ViewChild('myswing1') swingStack: SwingStackComponent;
@ViewChildren('mycards1') swingCards: QueryList<SwingCardComponent>;
cards: Array<any>;
stackConfig: StackConfig;
constructor() {
this.stackConfig = {
throwOutConfidence: (offset: number, targetElement: HTMLElement) => {
// you would put ur logic based on offset & targetelement to determine
// what is your throwout confidence
return 1;
},
minThrowOutDistance: 700 // default value is 400
};
this.cards = [
{ name: 'clubs', symbol: '♣' },
{ name: 'diamonds', symbol: '♦' },
{ name: 'spades', symbol: '♠' }
];
}
ngAfterViewInit() {
// ViewChild & ViewChildren are only available
// in this function
console.log(this.swingStack); // this is the stack
console.log(this.swingCards); // this is a list of cards
// we can get the underlying stack
// which has methods - createCard, destroyCard, getCard etc
console.log(this.swingStack.stack);
// and the cards
// every card has methods - destroy, throwIn, throwOut etc
this.swingCards.forEach((c) => console.log(c.getCard()));
// this is how you can manually hook up to the
// events instead of providing the event method in the template
this.swingStack.throwoutleft.subscribe(
(event: ThrowEvent) => console.log('Manual hook: ', event));
this.swingStack.dragstart.subscribe((event: DragEvent) => console.log(event));
this.swingStack.dragmove.subscribe((event: DragEvent) => console.log(event));
}
// This method is called by hooking up the event
// on the HTML element - see the template above
onThrowOut(event: ThrowEvent) {
console.log('Hook from the template', event.throwDirection);
}
}
See angular2-swing-example repository for the full example
FAQs
Angular 2 Component for Swing (Tinder style cards)
The npm package angular2-swing receives a total of 284 weekly downloads. As such, angular2-swing popularity was classified as not popular.
We found that angular2-swing demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.