# Ionic ngClass not working (fixed)

**URL:** <https://forum.ionicframework.com/t/ionic-ngclass-not-working-fixed/101971>\
**Category:** ionic-v3\
**Created:** [August 14, 2017, 10:09pm UTC](https://forum.ionicframework.com/t/ionic-ngclass-not-working-fixed/101971 "2017-08-14T22:09:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![samuelpodina](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/samuelpodina/32/115801_2.png) [@samuelpodina](https://forum.ionicframework.com/u/samuelpodina)\
**Post date:** [August 14, 2017, 10:09pm UTC](https://forum.ionicframework.com/t/ionic-ngclass-not-working-fixed/101971/1 "2017-08-14T22:09:44Z")

</div>

I am fairly new to ionic so excuse my newbie question. I searched all over for a solution and tried different things none with success and I can’t figure what I am missing.

I have a button which calls a function on click which toggles a boolean variable true/false

```auto
<button class="button" (click)="activate();"><i class="icon-font-size"></i></button>

```

I than added ngClass on a div that will add or remove class basest on the boolean var value

```auto
<div class="text-settings" [ngClass]="{'open': active === true}">
...
</div>

```

In the TS file of the page I have

```auto
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';

/*
  Generated class for the SinglePost page.

  See http://ionicframework.com/docs/v2/components/#navigation for more info on
  Ionic pages and navigation.
*/

@Component({
  selector: 'page-single-post',
  templateUrl: 'single-post.html',
})

export class SinglePostPage {

  selectedItem: any;
  active : boolean = false;

  constructor(public navController: NavController, public navParams2: NavParams) {
    this.selectedItem = navParams2.get('item');
  }

  activate() {
    this.active = !this.active;
    console.log(this.active);
  }

}

```

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [August 14, 2017, 10:37pm UTC](https://forum.ionicframework.com/t/ionic-ngclass-not-working-fixed/101971/2 "2017-08-14T22:37:42Z")

</div>

What you posted here works, so if you are having a problem with it, the problem lies elsewhere. That being said, it could be simplified to:

```auto
<div [class.open]="active">

```

---

<div class="post-metadata">

**Author:** ![samuelpodina](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/samuelpodina/32/115801_2.png) [@samuelpodina](https://forum.ionicframework.com/u/samuelpodina)\
**Post date:** [August 14, 2017, 10:57pm UTC](https://forum.ionicframework.com/t/ionic-ngclass-not-working-fixed/101971/3 "2017-08-14T22:57:41Z")

</div>

Thanks for you quick response. The problem must be elsewhere than I’ll keep digging. I recently updated Ionic’s version to the latest maybe I missed something in the setup.

This what I get from ionic info in case you spot anything, I’ll keep searching tho. Thanks again!

```auto
cli packages: (node_modules)

    @ionic/cli-plugin-cordova : 1.6.2
    @ionic/cli-plugin-ionic-angular : 1.4.1
    @ionic/cli-utils : 1.7.0
    ionic (Ionic CLI) : 3.7.0

global packages:

    Cordova CLI : 7.0.1

local packages:

    @ionic/app-scripts : 2.1.3
    Cordova Platforms : ios 4.4.0
    Ionic Framework : ionic-angular 3.6.0

System:

    Node : v6.5.0
    OS : macOS Sierra
    Xcode : Xcode 8.3.3 Build version 8E3004b
    ios-deploy : 1.9.1
    ios-sim : 5.0.13
    npm : 3.10.3

```

---

<div class="post-metadata">

**Author:** ![samuelpodina](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/samuelpodina/32/115801_2.png) [@samuelpodina](https://forum.ionicframework.com/u/samuelpodina)\
**Post date:** [August 15, 2017, 1:36pm UTC](https://forum.ionicframework.com/t/ionic-ngclass-not-working-fixed/101971/4 "2017-08-15T13:36:04Z")

</div>

I think I found the problem because I upgraded form ionic 2 to 3 I was missing the `IonicPage` import on this line `import { NavController, NavParams } from 'ionic-angular';` added that and it started working. Thanks @rapropos for your input.

so that second line in the TS file should have been

```auto
import { IonicPage, NavController, NavParams } from 'ionic-angular';

```
