0

I am using angular-fullstack which comes packed with Authentication already set up. there is a handy function getCurrentUser() which allows me to do something like:

<input ng-bind="getCurrentUser.name"/>

And I will get the name of the active user.

What I would like to do is attach the users name to another object in my scope. Something like this:

$scope.activeUser = $scope.getCurrentUser();

However I am not sure how to go about joining active user with the getCurrentUser() function.

Daimz
  • 3,243
  • 14
  • 49
  • 76

1 Answers1

0

Define activeUser as an array of elements then add only the ids. When needed do something like this:

$scope.activeUser = [];

if (isActive()) {
    var currentUser = $scope.getCurrentUser();

    $scope.activeUser.push(currentUser.id);
}

isActive() is a function you should create to define if the user is active or not. Then you need another condition or a "else" to remove user isn't active anymore.

EDIT: of course you can add the entire object if needed to the array you do that with:

  $scope.activeUser[currentUser.id] = currentUser;

Then you can get it back on the view with:

  <span>{{ activeUser[TheId] }}</span
michelem
  • 14,430
  • 5
  • 50
  • 66
  • I tried this: `$scope.activeUser = []; if (isActive()) { var currentUser = $scope.getCurrentUser(); $scope.activeUser.push(currentUser.id); } $log.info($scope.activeUser)` But I can get it to work it just returns: `ReferenceError: isActive is not defined` – Daimz Apr 14 '15 at 04:09
  • I figured it out: `$scope.task.createdBy = Auth.getCurrentUser()._id;` I rather than using `getCurrentUser()` I did `Auth.getCurrentUser()` and injected Auth in to the controller. – Daimz Apr 14 '15 at 04:43