Call static function from angular2 template

后端 未结 4 2118
滥情空心
滥情空心 2020-12-05 06:22

I\'m trying to build \'utility\' services (classes) for an angular project. The utility classes have static functions (so we don\'t have to instantiate needless objects).

4条回答
  •  温柔的废话
    2020-12-05 06:56

    Only instance members of the components class can be called from the view.

    If you want to call static members, you need to provide a getter in the component.

    export class MyComponent {
      parseDate = DateService.parseDate;
    }
    

    then you can use it like

    (input)="event.date=parseDate($event.target.value)"
    

提交回复
热议问题