angular2-pipe

Cannot Instantiate DatePipe

旧街凉风 提交于 2019-11-27 09:07:27
I am trying to instantiate a DatePipe object in my Angular2 app to use transform(...) function in a component I'm developing. // ... import { DatePipe } from '@angular/common'; @Component({...}) export class PanelComponent implements OnInit { // ... datePipe: DatePipe = new DatePipe(); // Error thrown here // ... } This code segment worked fine in RC5. Now I am trying to upgrade to Angular2 final release and getting this error when I run ng serve or ng build , ~/tmp/broccoli_type_script_compiler-input_base_path-XitPWaey.tmp/0/src/app/panel/panel.component.ts (33, 24): Supplied parameters do

How do I call an Angular 2 pipe with multiple arguments?

懵懂的女人 提交于 2019-11-27 06:19:45
I know I can call a pipe like this: {{ myData | date:'fullDate' }} Here the date pipe takes only one argument. What is the syntax to call a pipe with more parameters, from component's template HTML and directly in code? Eran Shabi In your component's template you can use multiple arguments by separating them with colons: {{ myData | myPipe: 'arg1':'arg2':'arg3'... }} From your code it will look like this: new MyPipe().transform(myData, arg1, arg2, arg3) And in your transform function inside your pipe you can use the arguments like this: export class MyPipe implements PipeTransform { transform

The pipe ' ' could not be found angular2 custom pipe

不想你离开。 提交于 2019-11-27 00:29:31
I can't seem to fix this error. I have a search bar and an ngFor. I am trying to filter the array using a custom pipe like this: import { Pipe, PipeTransform } from '@angular/core'; import { User } from '../user/user'; @Pipe({ name: 'usersPipe', pure: false }) export class UsersPipe implements PipeTransform { transform(users: User [], searchTerm: string) { return users.filter(user => user.name.indexOf(searchTerm) !== -1); } } Usage: <input [(ngModel)]="searchTerm" type="text" placeholder="Search users"> <div *ngFor="let user of (users | usersPipe:searchTerm)"> ... </div> Error: zone.js:478

Dynamic pipe in Angular 2

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 20:56:07
问题 I'm trying to create a component where you can pass which pipe that should be used for a list inside the component. From what I could find by testing and looking around for answers the only solution appears to create something like: <my-component myFilter="sortByProperty"></my-component> my-component template: <li *ngFor="#item of list | getPipe:myFilter"></li> Which then maps myFilter to the correct pipe logic and runs it, but this seems a bit dirty and not optimal. I thought they would have

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:

Cannot Instantiate DatePipe

岁酱吖の 提交于 2019-11-26 17:48:20
问题 I am trying to instantiate a DatePipe object in my Angular2 app to use transform(...) function in a component I'm developing. // ... import { DatePipe } from '@angular/common'; @Component({...}) export class PanelComponent implements OnInit { // ... datePipe: DatePipe = new DatePipe(); // Error thrown here // ... } This code segment worked fine in RC5. Now I am trying to upgrade to Angular2 final release and getting this error when I run ng serve or ng build , ~/tmp/broccoli_type_script

The pipe &#39; &#39; could not be found angular2 custom pipe

喜欢而已 提交于 2019-11-26 12:24:00
问题 I can\'t seem to fix this error. I have a search bar and an ngFor. I am trying to filter the array using a custom pipe like this: import { Pipe, PipeTransform } from \'@angular/core\'; import { User } from \'../user/user\'; @Pipe({ name: \'usersPipe\', pure: false }) export class UsersPipe implements PipeTransform { transform(users: User [], searchTerm: string) { return users.filter(user => user.name.indexOf(searchTerm) !== -1); } } Usage: <input [(ngModel)]=\"searchTerm\" type=\"text\"

How do I call an Angular 2 pipe with multiple arguments?

北战南征 提交于 2019-11-26 07:18:57
问题 I know I can call a pipe like this: {{ myData | date:\'fullDate\' }} Here the date pipe takes only one argument. What is the syntax to call a pipe with more parameters, from component\'s template HTML and directly in code? 回答1: In your component's template you can use multiple arguments by separating them with colons: {{ myData | myPipe: 'arg1':'arg2':'arg3'... }} From your code it will look like this: new MyPipe().transform(myData, arg1, arg2, arg3) And in your transform function inside your