Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use return value of a function as a string in Angular 2

This is the markup I want to place the returned value:

<h2>{{getSelectedUserName}}</h2>

This is the function I want to use, which returns a string:

public getSelectedUserName(): string {
    let firstName = this.selectedUser.name.split("\\s+")[0];

    console.log(this.selectedUser.name.split("\\s+"));
    console.log(firstName);
    return firstName;
}
like image 519
CommonSenseCode Avatar asked Aug 25 '16 22:08

CommonSenseCode


1 Answers

You're not calling the function. You need

{{ getSelectedUserName() }}
like image 117
JB Nizet Avatar answered Nov 15 '22 22:11

JB Nizet