We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

get user first name inside of widget

Brook3
Giga Expert

I want to display first name of current user inside of widget.

inside of widget

HTML

<p>Hello, {{firstName}}</p>

SERVER SCRIPT

(function() {
var firstName = gs.getUser().getFirstName();
})();

 

What is wrong? I have tried many ways but have not been successful.

1 ACCEPTED SOLUTION

Raghav Sharma24
Giga Patron

Try: 

Do not declare data, as it is already declared as server side object.

server:

data.firstName = gs.getUser().getFirstName();

HTML:

<p>Hello, {{data.firstName}}</p>

View solution in original post

3 REPLIES 3

Raghav Sharma24
Giga Patron

Try: 

Do not declare data, as it is already declared as server side object.

server:

data.firstName = gs.getUser().getFirstName();

HTML:

<p>Hello, {{data.firstName}}</p>

Ashutosh Munot1
Kilo Patron

HI,

IN Server code you should be always using data.XXXX and then in widget html you can access that data.xxxx in{{}}

 

Thanks,
Ashutosh

Swapnil Soni1
Giga Guru

Hi Brook,

You should be able to get the user's first name from the scope, so write your client controller like this:

function($scope) {

var c = this;

c.welcome = $scope.user.first_name ;

}

 

 

 

And in HTML, in which field you want to get the data you can use this. {{c.welcome}}

So on this field you get the first name.

If this helps you then please mark correct or helpful.

Thanks

Swapnil