2

I have an inventory page that also contains a password field. I would like to hide the password when the page is loaded, best would be to have points displayed **** and after click password is shown or a pop up.

JS

   var get_cert = function () {
        $http.get($scope.url.cert_list).then(
            function (response) {
                $scope.certs = response.data;
            }
        );
    }
    // execute get function
    get_cert();

HTML

<div class="panel panel-default">
    <table class="table table-striped valign_middle">
        <tr class="table_header">
            <td>Name</td>
            <td>Pass</td>
        </tr>
        <tr ng-repeat="cert in certs | filter:search | orderBy:['name']">
            <td>{{cert.name}}</td>
            <td>
                <button class="w3-btn w3-black w3-hover-green w3-ripple" ng-click="get_cert()">Show</button>
                 <span ng-show="get_cert()">{{cert.password}}</span>
            </td>

        </tr>
    </table>

1 Answer 1

2
<button ng-show="!cert.showPw" class="w3-btn w3-black w3-hover-green w3-ripple" ng-click="cert.showPw = true">Show</button>
<span ng-show="cert.showPw">{{cert.password}}</span>

You can use ng-click to do cert.showPw = true, which will append a property called showPw (a boolean) to the object. Combined with ng-show, you can easily switch between the two.

This way you'll keep your controller free of any additional logic needed. You may include ng-click on the span which holds the password which will set showPw = false to switch it back to a button.

See my JSFiddle for full example.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.