angular-pipe

Angular 5 Pipe, {updateOn:'blur'} not updating model as expected

百般思念 提交于 2021-01-29 19:20:11
问题 I've created a custom pipe in Angular 5 that updates the display of an input field on blur. The value of the input field is converted and displayed, but the value of the model is not updated properly. This is the functionality I am expecting, is there a way to achieve this with a pipe? Stackblitz - Link to Sample Code Steps to Reproduce the issue. Remove the existing value and type in any number and click outside the field. (Eg: 242235.34234) The input and the model values do not match. HTML

Convert timestamp to date using Angular 2 pipes

落花浮王杯 提交于 2021-01-20 20:48:16
问题 I'm trying to convert a timestamp to a date format using Angular pipes. I wrote this in the HTML template: {{myTimestamp | date}} Where myTimestamp is of type number. I get unexpected results, for example the timestamp 1468251287 (Which matches Nov 7, 2016) is displayed as Jan 18, 1970 . I would like to know how I can fix this issue. 回答1: As mentioned by @Perry you will need to provide the date in milliseconds. From the Angular 2 reference for date we have: expression is a date object or a

Search for a string in all properties of an object in Angular 2

霸气de小男生 提交于 2020-12-25 08:51:13
问题 How to search for a string in all properties of an object in Angular 2 with TS. I have an array of customers rendered in a table with a search box, if the user types a value I want to search for all properties values to push a customer that matches the value typed. export var CUSTOMER: Client[] = [ { id: 1, name: 'John', phone: '888-888-888'}, { id: 2, name: 'Nick', phone: '555-888-888'}, { id: 3, name: 'Mike', phone: '666-888-888'}, ]; The Filter Pipe import {Pipe, PipeTransform, Injectable}

Search for a string in all properties of an object in Angular 2

徘徊边缘 提交于 2020-12-25 08:48:19
问题 How to search for a string in all properties of an object in Angular 2 with TS. I have an array of customers rendered in a table with a search box, if the user types a value I want to search for all properties values to push a customer that matches the value typed. export var CUSTOMER: Client[] = [ { id: 1, name: 'John', phone: '888-888-888'}, { id: 2, name: 'Nick', phone: '555-888-888'}, { id: 3, name: 'Mike', phone: '666-888-888'}, ]; The Filter Pipe import {Pipe, PipeTransform, Injectable}

Is unsubscribe needed if an Observable uses an async pipe?

馋奶兔 提交于 2020-07-09 09:08:16
问题 I need to determine whether two different approaches for handling Observables are equally valid, or if one will cause memory issues. In the following example, foo$ and bar are template variables that receive their values from a service. Each has its own Observable. In the component, bar is explicitly given its value from a subscription and later ends that subscription in OnDestroy() . foo$ , however, does not explicitly subscribe to a service but rather uses an async pipe in the template. Are

Is unsubscribe needed if an Observable uses an async pipe?

末鹿安然 提交于 2020-07-09 09:05:13
问题 I need to determine whether two different approaches for handling Observables are equally valid, or if one will cause memory issues. In the following example, foo$ and bar are template variables that receive their values from a service. Each has its own Observable. In the component, bar is explicitly given its value from a subscription and later ends that subscription in OnDestroy() . foo$ , however, does not explicitly subscribe to a service but rather uses an async pipe in the template. Are