angular2-custom-pipes

Bind component variable to pipe filter

≡放荡痞女 提交于 2019-12-11 07:04:12
问题 i have a problem when passing values to my pipe filter. I need to pass an argument value in the form of a variable called pagex from my component and I cant find the syntax to make it work... or I'm missing something. Thanks for the help. myComponent export class ItemsComponent { items:any[] pagex:number; constructor(private ItemService:ItemService){ this.ItemService.getItems() .subscribe(items =>{ this.items=items; this.pagex=2; }); } The following, passing the value manually, works: <div

Angular custom pipe not be found

*爱你&永不变心* 提交于 2019-12-03 21:30:46
问题 In my application I need a custom pipe globally, I try to implement it following angular pipe but i see always this error Template parse errors: The pipe 'formatdate' could not be found formatdate.pipe import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'formatdate' }) export class FormatdatePipe implements PipeTransform { transform(dateJson: any, args?: any): any { . //code... . return dateJson; } } } app.module import { FormatdatePipe } from './shared/pipes/formatdate.pipe';

Custom Pipe | filter for calculating relative time in angular2

 ̄綄美尐妖づ 提交于 2019-12-02 18:34:50
问题 During the learning process, I came across Creation of Custom Pipe , so I thought this will help. 回答1: Below is the code for custom pipe. import{PipeTransform,Pipe} from '@angular/core'; @Pipe({ name:'relativeTime' }) export class RelativeTimeFilterPipe implements PipeTransform{ transform(inputDate:string):string{ var current = new Date().valueOf(); var input = new Date(parseInt(inputDate)).valueOf(); var msPerMinute = 60 * 1000; var msPerHour = msPerMinute * 60; var msPerDay = msPerHour * 24