0.0.6 • Published 6 years ago

different-pipes v0.0.6

Weekly downloads
1
License
MIT
Repository
-
Last release
6 years ago

Different pipes for Angular

This project is a collection of pipes to be used in Angular projects

List of pipes available and parameters (required and optional)

. SortArrayByOneNumeralPropertyPipe:
    - value: Array<any>;
    - propertyName: string;

. SortArrayByTwoNumeralPropertyPipe
    - value: Array<any>;
    - firstPropertyName: string;
    - secondPropertyName: string;
    - limit?: number;

1- Import the MODULE

import { SortArrayByOneNumeralPropertyModule } from 'different-pipes'; 

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    SortArrayByOneNumeralPropertyPipeModule,
    SortArrayByTwoNumeralPropertyPipeModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

2- Example of variables in the CONTROLLER

heroes: Array<any> = [
    {name: 'Jack', order: 2},
    {name: 'Thon', order: 6},
    {name: 'Eduard', order: 1},
    {name: 'Jhon', order: 5},
    {name: 'Rita', order: 4},
    {name: 'Peter', order: 3},
  ];

priority: Array<any> = [
    {name: 'House', order: 1, value: 101},
    {name: 'Car', order: 2, value: 101},
    {name: 'Hollidays', order: 2, value: 100},
    {name: 'Beer', order: 1, value: 104},
    {name: 'Water', order: 1, value: 103},
    {name: 'Horse', order: 3, value: 100},
  ];

3- Example of use in the HTML

<div>
  <p>sortArrayByOneNumeralPropertyPipe: sort by property "order":</p>
  <p *ngFor="let item of heroes | sortArrayByOneNumeralProperty: 'order'">{{item.name}}</p>
</div>

<div>
  <p>sortArrayByTwoNumeralPropertyPipe: sort by properties "order" & "value" with optional parameter limit to 3:</p>
  <p *ngFor="let item of priority | sortArrayByTwoNumeralProperty : 'order' : 'value' : 3">{{item.name}}</p>
</div>