Animating with Angular 2

As I delve into this informative resource, my goal is to incorporate some animations into my applications, but I find myself grappling with understanding how the animations are triggered.

HTML Component

<div class="navbar navbar-default navbar-fixed-top">
    <ul class="nav navbar-nav">
        <li>
            <span (click)="open()" class="glyphicons glyphicons-show-lines">open</span>
        </li>
    </ul>
</div>
<div class="vertical-menu" @verticalOpen="openOrClose">
    <div class="list-group table-of-contents">
        <a class="list-group-item" [routerLink]="['/login']" routerLinkActive="active">Login</a>
        <a class="list-group-item" [routerLink]="['/personalArea']" routerLinkActive="active">Personal Area</a>
    </div>
</div>

TS File

@Component({
   selector:'menu-bar',
   templateUrl:'app/components/menubar/menubar.component.html',
   styleUrls:['app/components/menubar/menubar.component.css'],
   directives:[ROUTER_DIRECTIVES],
   animations:[
       trigger('verticalOpen',[
           state('inactive',style({
               left: '-115px',
               transform:'scale(1)',
               backgroundColor:'red'
           })),
           state('active',style({
               left: '0px',
               transform:'scale(1.3)'
           })),
           transition('active => inactive', animate('100ms ease-in')),
           transition('inactive => active', animate('100ms ease-out'))
       ])
   ]
})
export class MenuBar{
    closeOrOpen:string;
    open(){
        if(this.closeOrOpen=='inactive'){
            this.closeOrOpen='active'
        }
        else if(this.closeOrOpen=='active'){
            this.closeOrOpen='inactive'    
        }
        else{
            this.closeOrOpen='inactive'
        }
        console.log(this.closeOrOpen)
    }
}

My aim is to trigger a style change with a button, yet when I click, nothing seems to happen. Upon reviewing the code provided, no errors jump out at me. Can anyone spot what might be missing or incorrect in my approach?

Answer №1

The code snippet in your template appears as follows:

@verticalOpen="openOrClose" 

Therefore, within your open function, make sure to switch the value of the openOrClose property rather than the closeOrOpen property.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Typescript is missing Zod and tRPC types throughout all projects in the monorepo, leading to the use of 'any'

Recently, I've found myself stuck in a puzzling predicament. For the last couple of weeks, I've been trying to troubleshoot why the types are getting lost within my projects housed in a monorepo. Even though my backend exposes the necessary types ...

Determine whether an array is void, then proceed to deactivate a button

I am attempting to prevent a button from being clickable if an array is empty, but I am encountering difficulties. <button [disabled]="(users.length ==0 )?true:false">Send mass emails</button> Within the TypeScript file: users: UsersModel[]; ...

Running a function upon page refresh in Angular10 using Typescript

Currently, I am developing a project with Angular 10 and facing a challenge. My goal is to navigate to a different component using (router.navigate) only upon refreshing or reloading the page. Are there any suggestions on how to accomplish this in Angular? ...

Break down the provided Array type into distinct new types

If we have a specific type defined as: type Tuple = [name: string, age: number, address: string]; and we are interested in creating a new type without the first element, like this: type NewTuple = [age: number, address: string]; Is there a way to achieve ...

Learn how to easily reset the index value within the same template in Angular

In my template, I have 3 tables with the same JSON data as their parent elements. <tbody> <ng-container *ngFor="let row of reportingData.RecommendationData; let i=index"> <tr *ngIf="row.swRecommendations"> <td& ...

Angular does not display HTML content until the requested http data has been fully loaded

I am experiencing an issue where certain HTML content does not load until the component has received data from an API call through a service. Below is the relevant code snippet: import { ApiService } from './services/api.service'; @Component({ ...

Vue 3 - Child Component Script Not Updating with Reactive Prop Changes

I am facing an issue where I am trying to pass a reactive data as a prop to a child component in Vue 3. The data updates correctly in the child component's template, but it does not reflect in the child component's script. In the parent component ...

Struggling with setting up the onChange function in a Next.js application

After successfully writing and testing the code here, I encountered an error preventing me from building it. Please review the code for any issues. I am attempting to set onChange to handle user input in a text field. Currently using onChange={onChange}, ...

How to hide ion-input when typing in Ionic 3

I am looking for a way to customize the output of an ion-input field. Instead of displaying what the user is typing, I want to only show the result of a function called formatNum when ngModelChange is triggered. This means that the actual input from the ...

Incorporate the angular-cdk table functionality seamlessly with the sleek design of Bootstrap

Looking to enhance the design of my Angular application by incorporating Bootstrap table styling with the use of Angular CDK table (without Angular Material2). One challenge I've encountered is that while it's possible to add classes to the CDK ...

What could be causing the inner array typescript to be inaccessible in an Angular 5 application?

Below are the JSON definitions that I am working with: export class Company { name: string; trips : Trip[] = []; } export class Trip{ id: number; name: string; } Within the component, there is a method that contains the ...

Ensure that you are completely logged out of all browser tabs when one tab has been successfully logged out

Just started working with Angular 4 and have built an application with a login page and home page. Upon successful login, I navigate to the home page. I noticed that if my application is open in multiple tabs and I log out from one tab, clicking on any ot ...

Executing functions before the data is loaded in an Angular application

Hey there, I'm relatively new to Angular and I've been facing some difficulties when it comes to loading data. In the code snippet below, you'll notice that I have two services being called. Each service logs something to the console. After ...

Nuxt encountered an issue with Vue hydration: "Tried to hydrate existing markup, but the container is empty. Resorting to full mount instead."

I'm facing an issue while trying to integrate SSR into my project. I keep encountering this error/warning. How can I pinpoint the problem in my code? There are numerous components in my project, so I'm unsure if I should share all of my code, b ...

Warning: An alert has been triggered while generating files using create-react-app

npm WARN <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e896999d9c81849ba8dbccd1ded8d4cfdcd0c59bc6cbca">[email protected]</a> requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= ...

What is the best way to assign unique IDs to automatically generated buttons in Angular?

Displayed below is a snippet of source code from an IONIC page dedicated to shapes and their information. Each shape on the page has two buttons associated with it: shape-properties-button and material-information-button. Is it possible to assign different ...

What is the best way to make cypress.io swipe an ionic ion-item-sliding component to the left?

I am currently working on a small ionic 4 (vue) app that includes an ion-list with ion-item-sliding. Here is a snippet of the code: HTML <ion-item-sliding v-for="day in month.days" v-bind:key="day.day"> <ion-item :id ...

Can HTML tag attributes be accessed in CSS within the Shadow-DOM?

As I work on developing a custom component using StencilJS, I find myself needing to adjust the outline behavior when users navigate through it with either a keyboard or mouse. My component employs ShadowDOM and I aim to extract an HTML tag attribute from ...

The latest version, Angular 13, introduced numerous enhancements to caching in Angular applications

I recently made the switch to Angular 13 and noticed an abundance of cache files in a folder called .angular\cache\13.3.10 Within this folder, I found two sub directories: - angular-webpack - babel-webpack After manually upgrading from versio ...

Executing jasmine tests in Visual Studio Code - a step by step guide

After setting up visual studio code with jasmine and typescript installed, I have created a spec file named TestSpec.ts. describe("Testing", () =>{ it("should pass", () =>{ let msg = "Welcome to TypeScript"; //I want to print the msg firs ...