ここでは、通知をアクティブ/非アクティブに設定するためにトグルアイコンを使用しています。 getコールでは、0または1のいずれかの通知値を取得していますが、私のtsファイルは私がtrueを渡していることを意味するブール値であるnoteValueを使用しています。ionic2とangular2を使用して通知でイオントグルを使用する方法
しかし、データベース側から我々は、彼らが唯一のブールとして変数を渡し、データベース側を0または1のいずれかを取得しているが、私が合格した場合、誤っているためnoteValueトグルアイコン作業の0または1
として値を格納したデータベースは、意味アプリをリフレッシュするとtrueまたはfalseが表示され、false(トグルアイコン)はfalseのみを表示できます。また、トグルアイコンがアクティブな場合はfalse値を渡し、トグルアイコンはアクティブではありません。
HTML:
<ion-item no-lines >
<ion-label class="ion-label"> Notification</ion-label>
<ion-toggle (ionChange)="updateValue()" checked="noteValue"></ion-toggle></ion-item>
.TS:
export class NotificationPage {
public noteValue:boolean;
constructor(private navCtrl: NavController,private user:Users, private productServices:Products, private logger:Logger) {
var _this = this;
// get call
this.productServices. getNotification(function(data){
_this.logger.debug("checking my notification Details" +JSON.stringify(data));
console.log(data.notification);
_this.noteValue = data.notification[0];
console.log(data.notification[0]);
})
}
//post call
updateValue(){
var _this=this;
_this.noteValue = !_this.noteValue; // If _this.noteValue is equal to true, now it will be set to false. If it's false, it will be set to true.
let notificationDetails = {
notification: _this.noteValue
};
console.log(notificationDetails);
this.user.setNotification(notificationDetails, function (result, data) {
_this.logger.debug("checking my notification Details" +data);
if (result=='1') {
console.log(_this.noteValue);
//_this.noteValue=!_this.noteValue;
_this.logger.debug("checking my notification Details" +data);
alert("sucesscall for notification"+data.toString());
}
else {
_this.logger.info("failure Notification");
alert("failure for notification");
}
});
}
}