【发布时间】:2017-02-07 09:05:24
【问题描述】:
这里我使用切换图标来设置通知活动/非活动。我正在从 get call 获得响应。 在 get 调用中,我得到的通知值是 0 或 1,但我使用的 ts 文件 noteValue 是布尔值,意味着我们传递的 true 是 false。
但是从数据库端我们得到 0 或 1,数据库端它们仅将变量作为布尔值传递,但数据库将值存储为 0 或 1。
由于 noteValue 切换图标工作不正确,这意味着如果我在刷新应用程序时传递 true 或 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");
}
});
}
}
【问题讨论】:
标签: angular typescript ionic2