nx-primeng-sakai-v17/src/app/components/list/list.component.ts

68 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-12-29 06:28:51 +00:00
import { Component, OnInit } from '@angular/core';
import { SelectItem } from 'primeng/api';
import { Product } from '../../api/product';
import { ProductService } from '../../service/productservice';
2021-12-09 14:24:42 +00:00
@Component({
2021-12-28 10:29:25 +00:00
templateUrl: './list.component.html',
2021-12-23 11:15:00 +00:00
styleUrls: ['../../../assets/demo/badges.scss']
2021-12-09 14:24:42 +00:00
})
2021-12-28 10:29:25 +00:00
export class ListComponent implements OnInit {
2021-12-09 14:24:42 +00:00
products: Product[];
sortOptions: SelectItem[];
sortOrder: number;
sortField: string;
sourceCities: any[];
targetCities: any[];
orderCities: any[];
constructor(private productService: ProductService) {}
ngOnInit() {
this.productService.getProducts().then(data => this.products = data);
this.sourceCities = [
{name: 'San Francisco', code: 'SF'},
{name: 'London', code: 'LDN'},
{name: 'Paris', code: 'PRS'},
{name: 'Istanbul', code: 'IST'},
{name: 'Berlin', code: 'BRL'},
{name: 'Barcelona', code: 'BRC'},
{name: 'Rome', code: 'RM'}];
this.targetCities = [];
this.orderCities = [
{name: 'San Francisco', code: 'SF'},
{name: 'London', code: 'LDN'},
{name: 'Paris', code: 'PRS'},
{name: 'Istanbul', code: 'IST'},
{name: 'Berlin', code: 'BRL'},
{name: 'Barcelona', code: 'BRC'},
{name: 'Rome', code: 'RM'}];
this.sortOptions = [
{label: 'Price High to Low', value: '!price'},
{label: 'Price Low to High', value: 'price'}
];
}
onSortChange(event) {
const value = event.value;
if (value.indexOf('!') === 0) {
this.sortOrder = -1;
this.sortField = value.substring(1, value.length);
} else {
this.sortOrder = 1;
this.sortField = value;
}
}
}