Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use an alias name for Angular expression?

Tags:

angular

I am using Angular 7

I have following template

<div>
{{myService.userInfo.firstName}} {{myService.userInfo.lastName}}
</div>

I want to make it short by substituting user instead of myService.userInfo

<div>
{{user.firstName}} {{user.lastName}}
</div>

How can I do this like ng-init in AngularJS.

like image 495
Hari Das Avatar asked Dec 17 '22 19:12

Hari Das


1 Answers

create a getter property that will return the userinfo object

 get user(){
      return this.myService.userInfo;
 }

and use like

<div>
   {{user.firstName}} {{user.lastName}}
</div>
like image 74
Kishore Kumar Avatar answered Dec 28 '22 11:12

Kishore Kumar