2
votes

I have a DockLayout and two css classes. I change state.sideDrawer.isOpen but element's class does not change. When I console.log its class I see that first class it gets stays still. I tried setting its class in .ts file and it worked. But I need ngClass to work. What could be wrong?

I am using latest Angular CLI(7.2.1) and Nativescript(5.1.0).

Here is the Playground link : https://play.nativescript.org/?template=play-ng&id=oCeLRd

   <DockLayout #sideDrawer stretchLastChild="false" [ngClass]="{'sideDrawerOpen': state.sideDrawer.isOpen == true, 'sideDrawerClosed': state.sideDrawer.isOpen == false}" style="background-color: #3c3f47;width: 600px;padding: 0 0 5px 15px;"></DockLayout>

CSS:

@keyframes sideDrawerOpen {
   from  { transform: translate(-500, 0);}
   to { transform: translate(0, 0);}
}

@keyframes sideDrawerClosed {
   from  { transform: translate(0, 0);}
   to { transform: translate(-100, 0);}
}

.sideDrawerOpen{
   animation-name: sideDrawerOpen;
   animation-duration: 2s;
   animation-fill-mode: forwards;
}

.sideDrawerClosed{
   animation-name: sideDrawerClosed;
   animation-duration: 2s;
   animation-fill-mode: forwards;
}
2
Can you share a Playground sample of same? Also let's know which platform you are testing this now? - Manoj
I added requested links and information. - Hasan Triuman Tekin

2 Answers

2
votes

Your swipe event was executing outside Angular context, you must either use event binding in your HTML template Or use Renderer2 to add add event listener to the ElementRef in order for Angular to perform change detection.

Here is the updated Playground.

0
votes

I had a similar problem with a {N}-Angular app. For me the issue was because I had defined the ngClass css class above the default class in the .css file so it was getting imported first and overwritten by the default one. Switching the order of the classes solved the issue for me