Axl
Axl

Reputation: 67

ToggleClass using AngularJS

I'm trying to toggle a sidebar via toggling classes. In jQuery I had:

$("[data-toggle]").click(function () {
    var toggle_el = $(this).data("toggle");
    $(toggle_el).toggleClass("open-sidebar");
});

Wondering how I'd achieve the same thing with AngularJS

Upvotes: 0

Views: 1109

Answers (1)

tymeJV
tymeJV

Reputation: 104795

Use ng-class set to a variable:

ng-class="{'someClass' : scopeVar }"

And toggle scopeVar on a click:

$scope.toggle = function() { $scope.scopeVar = !$scope.scopeVar }

Upvotes: 1

Related Questions