angular-pipe

What is impure pipe in Angular?

こ雲淡風輕ζ 提交于 2019-11-28 06:15:29
@Pipe({name:'myPipe', pure: false}) I am unable to understand impure pipes, some what better with pure pipes. Please explain me with a simple and basic example? Günter Zöchbauer A pure pipe is only called when Angular detects a change in the value or the parameters passed to a pipe. An impure pipe is called for every change detection cycle no matter whether the value or parameters changes. This is relevant for changes that are not detected by Angular when you pass an array or object that got the content changed (but is still the same instance) when the pipe injects a service to get access to

Angular 4 Pipe Filter

≯℡__Kan透↙ 提交于 2019-11-27 12:43:58
I am trying to use a custom pipe to filter my *ngFor loop using an input field with ngModel. With my other custom pipe (sortBy), it works perfectly fine. However, the filter pipe seems to make it that none of the data appears. I'm still learning this, and I tried a few variations to no avail: -filter: term -filter: {{term}} -filter: 'term' -filter" {{'term'}} So I think the problem may lie elsewhere in the code. If anyone can help I'd really appreciate it. Here is my code: HTML Component <div style="text-align:center"> <h1> Welcome to {{title}}!! </h1> </div> <h2>Please choose your favorite

Is it possible to use a pipe in the code?

China☆狼群 提交于 2019-11-27 11:44:40
When I use my custom pipe in a template, it is like this: {{user|userName}} And it works well. Is it possible to use a pipe in the code? I try to use it like this: let name = `${user|userName}`; But it shows userName is not defined My alternative way is using db.collection.findOne() manually in the code. But is there any smart way? This is the way you can use @Pipe in a component: import { YourPipeComponentName } from '@angular/...'; class YourService { constructor(private pipe: YourPipeComponentName) {} YourFunction(value) { this.pipe.transform(value, 'pipeFilter'); } } Hongbo Miao @Siva is

What is impure pipe in Angular?

本小妞迷上赌 提交于 2019-11-27 05:37:09
问题 @Pipe({name:'myPipe', pure: false}) I am unable to understand impure pipes, some what better with pure pipes. Please explain me with a simple and basic example? 回答1: A pure pipe is only called when Angular detects a change in the value or the parameters passed to a pipe. An impure pipe is called for every change detection cycle no matter whether the value or parameter(s) changes. This is relevant for changes that are not detected by Angular when you pass an array or object that got the

Angular 4 Filter Search Custom Pipe

雨燕双飞 提交于 2019-11-27 05:13:01
So I am trying to build a custom pipe to do a search filter of multiple values in a ngFor loop. I have looked for a number of hours for a good working example, and most of them are based on previous builds and don't seem to work. So I was building the Pipe and using the console to give me the values. However, I cannot seem to get the input text to show up. Here are the previous places I have looked to find working examples: Angular 4 Pipe Filter http://jilles.me/ng-filter-in-angular2-pipes/ https://mytechnetknowhows.wordpress.com/2017/02/18/angular-2-pipes-passing-multiple-filters-to-pipes/

How to use pipes in Component

房东的猫 提交于 2019-11-27 04:06:35
问题 I want to use the datePipe in my component. I followed the instructions here but I am met with Error: StaticInjectorError[DatePipe]: StaticInjectorError[DatePipe]: NullInjectorError: No provider for DatePipe! Here is my code: Component import { DatePipe } from '@angular/common'; export class LivePreviewComponent implements OnInit{ currentDate = new Date(); constructor(private datePipe:DatePipe) {} ngOnInit() { this.datePipe.transform(this.currentDate, 'YYYY-MM-DDTHH:mm') } } 回答1: Add to

Angular2 use basic pipe in custom pipe

混江龙づ霸主 提交于 2019-11-26 21:13:55
问题 I'd like to add some additional functionality to the basic angular2 pipes. ie. some extra formatting done on the currency pipe. To do that I'd like to use the existing pipe in the component code of my custom pipe. Is there any way this can be done? @Pipe({name: 'formatCurrency'}) export class FormatCurrency implements PipeTransform { transform(value:number, args:string[]) : any { var formatted = value/100; //I would like to use the basic currecy pipe here. ///100 | currency:'EUR':true:'.2'

Angular 2 Pipe under condition

别来无恙 提交于 2019-11-26 20:05:03
问题 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? 回答1: You need to change the syntax a bit: {{variable.value ? (variable.text | SomePipe) : (variable.text | pipe2)}} Plunker example 回答2: 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:

Is it possible to use a pipe in the code?

混江龙づ霸主 提交于 2019-11-26 18:04:42
问题 When I use my custom pipe in a template, it is like this: {{user|userName}} And it works well. Is it possible to use a pipe in the code? I try to use it like this: let name = `${user|userName}`; But it shows userName is not defined My alternative way is using db.collection.findOne() manually in the code. But is there any smart way? 回答1: First declare the pipe in the providers of your module: import { YourPipeComponentName } from 'your_component_path'; @NgModule({ providers: [

Angular 4 Pipe Filter

扶醉桌前 提交于 2019-11-26 15:59:20
问题 I am trying to use a custom pipe to filter my *ngFor loop using an input field with ngModel. With my other custom pipe (sortBy), it works perfectly fine. However, the filter pipe seems to make it that none of the data appears. I'm still learning this, and I tried a few variations to no avail: -filter: term -filter: {{term}} -filter: 'term' -filter" {{'term'}} So I think the problem may lie elsewhere in the code. If anyone can help I'd really appreciate it. Here is my code: HTML Component <div