0

我有仪表板,我是超级管理员。我创建用户个人资料,我可以在其中查看我的所有个人资料数据。现在,我有所有用户的表,我想打开并在需要时编辑某些用户的用户配置文件。这是登录用户的呼叫用户配置文件()的html代码

<a href="#" class="btn btn-primary btn-block btn-sm" ui-sref="user-profile/:userID">{{'USER_PROFILE'| translate}}</a>

这是我调用状态参数的 ctrl

.controller('userProfileCtrl', ['$scope', '$stateParams', '$state', '$http','userProfileFactory',
 function ($scope, $stateParams, $state, $http, userProfileFactory) {
 $scope.authentication = authService.authentication;
$scope.userID = $scope.authentication.userID;
$stateParams.userID = $scope.userID;
$scope.user = userProfileFactory.get({user: $stateParams.userID});
  $scope.user.$promise.then(function (data){
     console.log(data.id);
     return data;
 }); 

现在我想在表中选择一些用户并打开他的个人资料

<tr ng-repeat="user in users|filter:f" such-href="user-profile/{{user.id}}">

并用这个 ctrl 调用一些用户配置文件

$http.get(serviceBase + 'users/'+ $stateParams.userID +'/aaaa/').success (function(data){
            $scope.media = data.media;
            });

这是 ui-state

.state('user-profile/:userID', {
                url: '/user-profile/:userID',
                templateUrl: 'aaaa/aaa/aaaae/user-profile.html',
                controller: 'aaaaCtrl'
            })

问题是,每当我打开用户个人资料时,我都会在个人资料中获取我的数据(超级管理员数据)。

4

1 回答 1

0

我为 user_id 设置了 $rootScope 以获取它以供全球使用。现在,当您启动应用程序时,您将获得已登录的用户。

$scope.authentication = authService.authentication;
$rootScope.user_id = $scope.authentication.userID;
$scope.user = userProfileFactory.get({user: $stateParams.userID});
 $scope.user.$promise.then(function (data){
     return data;
 });

现在在 html 中使用它。

such-href="user-profile/{{user_id}}. 

现在您已经登录了用户。

要让管理员像以前一样打开用户配置文件,但在工厂中使用 :USERID 代替。

<tr ng-repeat="user in users|filter:f" such-href="user-profile/{{user.id}}">
于 2016-08-30T09:05:33.240 回答