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.

4

1 回答 1

0

将 activeUser 定义为元素数组,然后仅添加 id。需要时执行以下操作:

$scope.activeUser = [];

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

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

isActive() 是您应该创建的一个函数,用于定义用户是否处于活动状态。然后您需要另一个条件或“其他”来删除用户不再处于活动状态。

编辑:当然,如果需要,您可以将整个对象添加到您使用的数组中:

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

然后,您可以通过以下方式将其重新显示在视图中:

  <span>{{ activeUser[TheId] }}</span
于 2015-04-13T16:58:06.423 回答