Skip to content Skip to sidebar Skip to footer

How To Access The Username Out Of A Ng-repeat

I have a list of users generated with ng-repeat and data from db, which works fine. Now when you click on a user, you get a popup box. I would like to display the name of the selec

Solution 1:

You don't access the user in the popup, you pass the user to the popup.

You are already sending the users id, just send the entire user. Use user.name and user._id after you've send it.

Solution 2:

Change this:

ng-click="showPopUpDeletionConfirmation($event, user._id);"

to this:

ng-click="showPopUpDeletionConfirmation($event, user);"

and access user object in the popup

EDIT:

You need also to change the showPopUpDeletionConfirmation with this:

$scope.showPopUpDeletionConfirmation = function (ev, user) {
        $mdDialog.show({
            controller: 'DialogDeleteUserController',
            templateUrl: 'confirmDeletion.tmpl.html',
            //parent: angular.element(document.body),
            locals: {
                userId: user._id,
                selectedUser: user.name,
            },
            targetEvent: ev,
            hasBackdrop: false,
        })
            .then(function (result) {
            if (result) {
                $scope.users = _.filter($scope.users, function (user) {
                    return user._id !== userId;
                })
            }
        });
     }

And then you can access the entire user object in the popup template with $scope.selectedUser or something like {{selectedUser.name}}

Post a Comment for "How To Access The Username Out Of A Ng-repeat"