Calling method from a Angular 2 class inside template

前端 未结 2 748
野性不改
野性不改 2020-12-11 15:09

I have a angular 2 application that has a class called User. This user has a attribute called deleted_at that is either null or contains a datetime, obviously the user is de

2条回答
  •  Happy的楠姐
    2020-12-11 15:47

    If the template you are refering to is from your component above you can simple do {{ name() }}. In Angular 2 you dont have to refer to your component first to call methods as it was in Angular 1 the case. In case your class is just a model that you have declared in your componet, you have to get the reference to that model first and then call your method {{ user.name() }}. However, if your method is just a plain getter I would just access a public property instead of calling a method there.

提交回复
热议问题