A
A
Alexey2014-10-31 10:54:05
JavaScript
Alexey, 2014-10-31 10:54:05

How to hide a table using angularr?

I have a link, when you click on it, the data is loaded, and a table appears under the link with this data, when you click again, you need to hide this table. How to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2014-10-31
Protko @Fesor

<div ng-controller="MyCtrl as my">
    <button ng-click="my.pressed = !my.pressed;my.loadData();">
    <table ng-show="pressed">
        <tr ng-repeat="row in my.data">...</tr>
    </table>
</div>

function MyCtrl(dataProvider) {
    var self = this;
   
    this.loadData = function () {
        if (!self.pressed) return;
        dataProvider().then(function(data) {
             self.data = data;
        });
    }
}

A
Andrey Zenkov, 2014-10-31
@andreyzenkov

Yes, just add a variable to the scope, for example $scope.tableShow = false;
At the end of the request, do - $scope.tableShow = !$scope.tableShow;(such a toggle)
And in the view use the directive ng-show="tableShow"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question