@nbxx/nb-input
Version:
Angular - nbinput
53 lines • 1.82 kB
JavaScript
import { Component, HostListener, Input } from "@angular/core";
import { NbSortingService } from "./nb-sorting.service";
export class NbSortingItemComponent {
constructor(sortingService) {
this.sortingService = sortingService;
// 修改箭头方向,传递事件
this._sorting = '';
this.subscription = this.sortingService.subscribe(ch => this._sorting = ch.code == this.code ? this._sorting : '');
}
onToggleSort(event) {
if (event) {
event.preventDefault();
}
if (this.code) {
switch (this._sorting) {
case 'asc':
this._sorting = 'desc';
break;
case 'desc':
this._sorting = '';
break;
default:
this._sorting = 'asc';
break;
}
this.sortingService.next({ code: this.code, sorting: this._sorting });
}
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
}
NbSortingItemComponent.decorators = [
{ type: Component, args: [{
selector: '[nb-sorting-item]',
template: `
<ng-content></ng-content>
<i *ngIf="!!code" class="pull-right fa"
[ngClass]="{'fa-sort-desc': _sorting === 'desc'
, 'fa-sort-asc': _sorting === 'asc'
, 'fa-sort text-muted': _sorting === ''}"></i>
`
},] },
];
/** @nocollapse */
NbSortingItemComponent.ctorParameters = () => [
{ type: NbSortingService }
];
NbSortingItemComponent.propDecorators = {
code: [{ type: Input }],
onToggleSort: [{ type: HostListener, args: ['click', ['$event'],] }]
};
//# sourceMappingURL=nb-sorting-item.component.js.map