ANGULAR 2/4 : call function for each row in NgFor

前端 未结 2 832
栀梦
栀梦 2021-01-25 23:29

i\'m learning AngularJS, and i need some help.

I have a template like this

    
2条回答
  •  自闭症患者
    2021-01-25 23:53

    this.data = dataFromSomewhere();
    this.dataOpt = this.data.map((d) => this.myFunction(d.id));
    
    {{dataOpt[i]}}

    The pipe variant:

    @Pipe({selector: myFunc})
    class MyPipy implements PipeTransform {
      transform(val:string) {
        return // do the same calculation here that you would do in `myFunction`;
      }
    }
    

    and use it like

    {{data | myPipe}}

    (the pipe needs to be registered in declarations of the module (or in an imported module)

提交回复
热议问题