如何在使用ionic2的通知中使用离子切换

时间:2016-12-10 05:15:52

标签: html angular ionic2

我正在离子2中做通知我已经采取了一个切换按钮并写了那个的get和post调用。

下面是我的HTML代码。

<ion-header>

  <ion-navbar>
    <ion-title>Notifications</ion-title>
  </ion-navbar>

</ion-header>

<ion-content padding>

 <ion-item no-lines (click)="Update()">
        <ion-label> Notification</ion-label>
            <ion-toggle checked={{notify}}  ></ion-toggle>
    </ion-item>
</ion-content>

下面是我的ts文件..

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';

 import { Logger } from '../../providers/logger/logger';

 import { Rest } from '../../providers/network/rest';



/*
  Generated class for the Notifications page.

  See http://ionicframework.com/docs/v2/components/#navigation for more info on
  Ionic pages and navigation.
*/
@Component({
  selector: 'page-notifications',
  templateUrl: 'notifications.html'
})
export class NotificationsPage {
    public noteValue;
    public notify : boolean;

    NotificationsArray=[];

  constructor(public navCtrl: NavController, 
                  public  logger: Logger,
              public    rest: Rest){

  }

  ionViewDidLoad() {
    this.rest.get('/getNotification')
    .subscribe((result)=>
    {
        console.log("checking getNotification"+JSON.stringify(result));
        //this.logger.debug(["getNotification"][0]["newsletter"]);
        if(result.status == '1'){
          if(result.notify == '1'){
          this.notify=true;
          console.log("success of getNotification");
          //this.NotificationsArray=result.data;
        }
        else{
          this.notify=false;
          console.log("error of getNotification");
        }
        }     
    })
  }



  Update(){
  let setNotificationObj = {
    newsletter:this.notify
  }
  this.notify = !this.notify;
  console.log("cheking setNotificationObj " + JSON.stringify(setNotificationObj));
  this.rest.post('/setNotification',setNotificationObj)
  .subscribe((result)=>
  {
    console.log("checking data of success " +JSON.stringify(result));
     if(result.status == '1'){

   }
      else{
      console.log("error");
         }
      });
    }
  }

我的接听电话正在工作,但是当我关闭并且在切换按钮上时,它在位置0处获得json错误。请检查我的电话..

0 个答案:

没有答案