How to change CSS classes in typescript?

Viewed 503

I am trying to change the following codes in javascript to typescript.I am unable to do that please help.

$(function () {
    $(".navigation_icon").click(function () {
        $(".navigation").toggleClass('navigation-open');
    });
});
1 Answers

If you are looking for an angular solution please provide more detail. Here is a solution to your question. First of all, In your ts file, you should define a boolean to keep the state of navigation, then you define a function to toggle the navigation state.

IsNavigationOpen : boolean = true;

navigationToggle(): void {
  IsNavigationOpen = !IsNavigationOpen;
}

then you can define a button to use the function and the last part is a condition to set a CSS class for your navigation bar.

<button onclick="navigationToggle" class="navigation_icon">

<div class="navigation {{IsNavigationOpen ? 'navigation-open' : 'navigation-closed'}}">
Related