angular-pipe

Ascending and Descending Sort in Angular 4

时光总嘲笑我的痴心妄想 提交于 2019-11-30 15:56:50
问题 Why is it that sort function is working : <th (click)="sort('transaction_date')">Transaction Date <i class="fa" [ngClass]="{'fa-sort': column != 'transaction_date', 'fa-sort-asc': (column == 'transaction_date' && isDesc), 'fa-sort-desc': (column == 'transaction_date' && !isDesc) }" aria-hidden="true"> </i></th> WHILE THIS ONE ISN'T WORKING : <th (click)="sort('user.name')">User <i class="fa" [ngClass]="{'fa-sort': column != 'user.name', 'fa-sort-asc': (column == 'user.name' && isDesc), 'fa

Ascending and Descending Sort in Angular 4

允我心安 提交于 2019-11-30 15:17:50
Why is it that sort function is working : <th (click)="sort('transaction_date')">Transaction Date <i class="fa" [ngClass]="{'fa-sort': column != 'transaction_date', 'fa-sort-asc': (column == 'transaction_date' && isDesc), 'fa-sort-desc': (column == 'transaction_date' && !isDesc) }" aria-hidden="true"> </i></th> WHILE THIS ONE ISN'T WORKING : <th (click)="sort('user.name')">User <i class="fa" [ngClass]="{'fa-sort': column != 'user.name', 'fa-sort-asc': (column == 'user.name' && isDesc), 'fa-sort-desc': (column == 'user.name' && !isDesc) }" aria-hidden="true"> </i></th> html <tr *ngFor="let

Applying a pipe or transform to a Reactive Form value

血红的双手。 提交于 2019-11-30 14:55:16
I'm building a simple reactive form. For simplicity, lets say the only data I want to display is a date. test.component.html <form novalidate [formGroup]="myForm"> <input type="date" formControlName="date"> </form> test.component.ts private date: Date = Date.now(); ngOnInit() { this.myForm = this.fb.group({ date: [this.date, [Validators.required]] }); } The input type=date field on the template requires the date to be in the format of 'yyyy-MM-dd'. The value in event is a JavaScript Date object. How can I modify the data at the template level so the input value is correct? What I've tried: One

angular keyvalue pipe sort properties / iterate in order

帅比萌擦擦* 提交于 2019-11-30 12:17:40
When using the Angular keyvalue pipe to iterate over an object's properties as follows: <div *ngFor="let item of object | keyvalue"> {{item.key}}:{{item.value}} </div> I have experienced an issue where the properties were not iterated in the order expected. And this comment suggests that I am not the only one to experience this issue: How to loop over object properties with ngFor in Angular Can someone advise what determines the order of iteration when using the keyvalue pipe please and how to force a specific iteration order? My ideal order of iteration is the order in which the properties

Applying a pipe or transform to a Reactive Form value

懵懂的女人 提交于 2019-11-29 19:29:11
问题 I'm building a simple reactive form. For simplicity, lets say the only data I want to display is a date. test.component.html <form novalidate [formGroup]="myForm"> <input type="date" formControlName="date"> </form> test.component.ts private date: Date = Date.now(); ngOnInit() { this.myForm = this.fb.group({ date: [this.date, [Validators.required]] }); } The input type=date field on the template requires the date to be in the format of 'yyyy-MM-dd'. The value in event is a JavaScript Date

Block Round Off using decimal pipe in angular 4

我的未来我决定 提交于 2019-11-29 16:36:50
Using angular 4, {{31.94 | number:'1.0-0'}} Output: 32 Any idea, how to block the round off. Expecting the result is 31 You need to create your custom pipe as DecimalPipe doesn't provide any floor feature. Plus you can add your decimal pipe in it. Your Custom Pipe: @Pipe({name: 'floor'}) export class FloorPipe implements PipeTransform { /** * * @param value * @returns {number} */ transform(value: number): number { return Math.floor(value); } } Use in template as: <span>{{ yournumber | floor | your_decimal_pipe }}</span> your.component.ts import { Component, Pipe, PipeTransform } from '@angular

Display number in Million or Thousand format in angular 4

时光怂恿深爱的人放手 提交于 2019-11-29 14:02:31
问题 I am trying to display number format in my angular 4 application. Basically what i am looking at is if the number is in 12.23 millions then it should display For e.g 12.2M (One decimal place) If the number is 50,000.123 then 50.1K How do i achieve that in angular. Do I need to write a directive ? Are there any inbuilt pipes in angular ? structure export interface NpvResults { captiveInsYear: number[]; captiveInsPremiumPaid: number[]; captiveInsTaxDeduction: number[]; captiveInsLoanToParent:

angular keyvalue pipe sort properties / iterate in order

半世苍凉 提交于 2019-11-29 11:26:20
问题 When using the Angular keyvalue pipe to iterate over an object's properties as follows: <div *ngFor="let item of object | keyvalue"> {{item.key}}:{{item.value}} </div> I have experienced an issue where the properties were not iterated in the order expected. And this comment suggests that I am not the only one to experience this issue: How to loop over object properties with ngFor in Angular Can someone advise what determines the order of iteration when using the keyvalue pipe please and how

Block Round Off using decimal pipe in angular 4

被刻印的时光 ゝ 提交于 2019-11-28 10:49:57
问题 Using angular 4, {{31.94 | number:'1.0-0'}} Output: 32 Any idea, how to block the round off. Expecting the result is 31 回答1: You need to create your custom pipe as DecimalPipe doesn't provide any floor feature. Plus you can add your decimal pipe in it. Your Custom Pipe: @Pipe({name: 'floor'}) export class FloorPipe implements PipeTransform { /** * * @param value * @returns {number} */ transform(value: number): number { return Math.floor(value); } } Use in template as: <span>{{ yournumber |

Angular 2 Pipe under condition

こ雲淡風輕ζ 提交于 2019-11-28 06:42:02
Is it possible in Angular 2 to apply a pipe under condition? I would like to do something like: {{ variable.text | (variable.value ? SomePipe : OtherPipe) }} If not, what is the preferred way to achieve this effect? You need to change the syntax a bit: {{variable.value ? (variable.text | SomePipe) : (variable.text | pipe2)}} Plunker example Since such syntax isn't supported, I think that the only way to do that is to implement another pipe to handle the condition: @Pipe({ name: 'condition' }) export class ConditionPipe { transform(val,conditions) { let condition = conditions[0]; let