Monday, April 24, 2017

Angular 2 Pipes– args are not arguments :-)

Today I lost some time investing an issue with Angular 2. I was creating an Angular pipe using Angular CLI. The code that was generated for me was the following:

Unfortunately I wrongfully assumed that the args keyword was refering to the arguments object we have in the JavaScript language. Turns out that this was a wrong assumption. Since Angular beta.16 the parameters are not passed as array to the transform() method anymore but instead as individual parameters:

{{ myData | translate:'arg1':'arg2' }}

export class TranslatePipe implements PipeTransform {   
  transform(value:any, arg1:any, arg2:any):any {

I would suggest to the Angular CLI team to change the name of the argument, because the args name causes confusion. Or is it just me?

No comments: