# Subscription does not change view immadiately

**URL:** <https://forum.ionicframework.com/t/subscription-does-not-change-view-immadiately/67212>\
**Category:** ionic-v3\
**Created:** [October 17, 2016, 11:38am UTC](https://forum.ionicframework.com/t/subscription-does-not-change-view-immadiately/67212 "2016-10-17T11:38:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sami\_analyst](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sami_analyst/32/103680_2.png) [@sami\_analyst](https://forum.ionicframework.com/u/sami_analyst)\
**Post date:** [October 17, 2016, 11:38am UTC](https://forum.ionicframework.com/t/subscription-does-not-change-view-immadiately/67212/1 "2016-10-17T11:38:25Z")

</div>

Hello folks,

I’m using the [Network](http://ionicframework.com/docs/v2/native/network/) native plugin to detect the network status (connected or not) and to detect a change in network status (onConnect and onDisConnect).

I want to disable some buttons when the network disconnects and also want to enable them when I have the connection back. Therefore the Network plugin has 2 functions called onConnect and onDisConnect which are returning a Observable. in the subscription of these functions, I want to change a class variable called **“isConnected”**. The Code below shows I want to manage this.

```
constructor(...){
....
    // network
    this.isConnected = Network.connection !== "none";
    this.connectSubscription = Network.onConnect().subscribe(()=>{
      this.updateConnection();
      Toast.showShortBottom("connected now !").subscribe();
    });
    this.disconnectSubscription = Network.onDisconnect().subscribe(()=>{
      this.updateConnection();
      Toast.showShortBottom("disconnected now !").subscribe();
    });
...}

  updateConnection(){
    this.isConnected = Network.connection !== "none";
  }

```

and my html file contains some buttons which have to enabled/disabled depending on the connection status **“isConnected”** …

```
...
      <button ion-button icon-only [disabled]="!isConnected" (click)="openModal()" shortVibrateOnTap>
        <ion-icon ios="ios-swap" md="ios-swap"></ion-icon>
      </button>
...
  <ion-col width-10>
    <button ion-button icon-only class="arrow-btn" [disabled]="!isConnected && onLastQuestion" (click)="fireSth()" shortVibrateOnTap>
      <ion-icon *ngIf="!onLastQuestion" ios="ios-arrow-forward" md="ios-arrow-forward"></ion-icon>
      <ion-icon *ngIf="onLastQuestion" ios="ios-arrow-dropright-circle-outline" md="ios-arrow-dropright-circle-outline"></ion-icon>
    </button>
  </ion-col>
...

```

now the onConnect and onDisConnect function firing, But my buttons does not get disabled immadiately … I first have to tap a button or do another action … How can I force the view to update the button status ???

running **ionic 2 rc 1**

---

<div class="post-metadata">

**Author:** ![mirkonasato](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mirkonasato/32/131398_2.png) [@mirkonasato](https://forum.ionicframework.com/u/mirkonasato)\
**Post date:** [October 17, 2016, 1:12pm UTC](https://forum.ionicframework.com/t/subscription-does-not-change-view-immadiately/67212/2 "2016-10-17T13:12:29Z")

</div>

Sounds like Angular change detection is not being triggered automatically. You could try calling [ApplicationRef.tick](https://angular.io/docs/ts/latest/api/core/index/ApplicationRef-class.html#!#tick-anchor) explicitly, after injecting `ApplicationRef` into your constructor.

---

<div class="post-metadata">

**Author:** ![sami\_analyst](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sami_analyst/32/103680_2.png) [@sami\_analyst](https://forum.ionicframework.com/u/sami_analyst)\
**Post date:** [October 17, 2016, 1:49pm UTC](https://forum.ionicframework.com/t/subscription-does-not-change-view-immadiately/67212/3 "2016-10-17T13:49:16Z")

</div>

thanks, that seems to work. Do you also know if this behavior is normal ? why doesn’t changedetecetion get fired after the end of a subscription ?

---

<div class="post-metadata">

**Author:** ![mirkonasato](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mirkonasato/32/131398_2.png) [@mirkonasato](https://forum.ionicframework.com/u/mirkonasato)\
**Post date:** [October 17, 2016, 2:07pm UTC](https://forum.ionicframework.com/t/subscription-does-not-change-view-immadiately/67212/4 "2016-10-17T14:07:22Z")

</div>

Not having to worry about triggering change detection manually is one of the nice new features of Angular 2 compared to AngularJS where you frequently had to use `$scope.$apply`. This “magic” detection of changes relies on a library called [zone.js](https://www.npmjs.com/package/zone.js). I guess for some reason that doesn’t work in this case.

It may be worth raising an issue in the [ionic-native](https://github.com/driftyco/ionic-native) project to see if they think this is something that can/should be improved.
