Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ionChange-仅检测Ionic 2中从视图到模型的更改_Android_Angular_Typescript_Ionic2_Reminders - Fatal编程技术网

Android ionChange-仅检测Ionic 2中从视图到模型的更改

Android ionChange-仅检测Ionic 2中从视图到模型的更改,android,angular,typescript,ionic2,reminders,Android,Angular,Typescript,Ionic2,Reminders,我有一个离子2应用程序,允许安排通知(提醒功能) 那么,这些问题是: 当用户进入提醒页面时,应检查 保存提醒 如果有保存的提醒(我当前正在使用 存储),时钟应显示提醒时间并保存 开关处于活动状态 否则,时钟应显示当前时间,并在 错误状态(已停用) 这很有效。我可以保存提醒,一切正常,也可以禁用它们 当我有一个保存的提醒并进入页面时,会出现问题,它会向我显示“提醒已保存”的通知,当然,实际发生的情况是,当我进入该页面时,它会首先确认是否有保存的提醒,如果是真的,则会激活切换。此切换链接到事件(

我有一个离子2应用程序,允许安排通知(提醒功能)

那么,这些问题是:

  • 当用户进入提醒页面时,应检查 保存提醒
  • 如果有保存的提醒(我当前正在使用 存储),时钟应显示提醒时间并保存 开关处于活动状态

  • 否则,时钟应显示当前时间,并在 错误状态(已停用)

这很有效。我可以保存提醒,一切正常,也可以禁用它们

当我有一个保存的提醒并进入页面时,会出现问题,它会向我显示“提醒已保存”的通知,当然,实际发生的情况是,当我进入该页面时,它会首先确认是否有保存的提醒,如果是真的,则会激活切换。此切换链接到事件
(ionChange)
,因为它是我用来处理提醒激活/停用的切换。 然后,每当我进入页面并有一个已保存的提醒时,它会将切换设置为true,然后作为默认值将其初始化为false,
(ionChange)
检测到有更改,事件会再次触发,这就是为什么它会结束我再次保存提醒的原因。

没那么糟糕,但我不应该每次进入时都保存提醒

我正在考虑使用
click
事件,而不是
ionChange
,但它没有起作用

这是我的代码:

HTML

<ion-content padding>
    <div class="selector">
        <ion-item>
            <ion-label>Recordatorio</ion-label>
            <ion-toggle class="toggle" [(ngModel)]="toggleStatus" checked="true" (click)="changeToggle()"></ion-toggle>
        </ion-item>
        <ion-item>
            <ion-label>Horario</ion-label>
            <ion-datetime
                pickerFormat="HH:mm"
                [(ngModel)]="time"
                (ngModelChange)="timeChanged()"
                cancelText="Cancelar"
                doneText="Aceptar">
            </ion-datetime>
        </ion-item>
    </div>
</ion-content>
我只包括了相关代码

简言之:我需要知道我是否只能从视图中触发
(ionChange)
,并防止它在从控制器检测到模型变化时被激活

谢谢你,这太提前了

我用:
(ngModelChange)
而不是
(ionChange)

    ionViewWillEnter(): void {

        this.setDefaultProperties();
    }

    public setDefaultProperties(): void {

        this.date = new Date();
        this.setDefaultPickerTime();
        this.setToggleStatus();
    }

    public setDefaultPickerTime(): void {

        this.storage.get('reminderTime')
            .then((result) => {

                if (result) {
                    this.time = result;
                } else {

                    let actualTime: string = this.actualFormattedTime();
                    this.time = actualTime;
                }
            })
            .catch((err) => {
                console.log(err);
            });
    }

    public setToggleStatus(): void {

        this.storage.get('reminderToggleStatus')
            .then((result) => {
                this.toggleStatus = result;
            })
            .catch((err) => {
                console.log(err);
            });
    }

    public timeChanged(): void {

        if (this.toggleStatus === true) {
            this.saveReminder();
        }
    }

    public changeToggle(): void {

        if (this.toggleStatus === true) {
            this.saveReminder();
        } else {
            console.log("deselecciono");
            this.deleteReminder();
            this.deleteStoredReminderData();
            this.showDeleteReminderMsg();
        }
    }

    public deleteReminder(): void {

        LocalNotifications.cancelAll()
            .then((succes) => {
                //
            })
            .catch((err) => {
                console.log(err);
            });
    }

    public deleteStoredReminderData(): void {

        this.storage.remove('reminderTime')
            .then(() => {
                console.log("Tiempo eliminado");
            })
            .catch((err) => {
                console.log(err);
            });

        this.storage.remove('reminderToggleStatus')
            .then(() => {
                console.log("Toggle status eliminado");
            })
            .catch((err) => {
                console.log(err);
            });
    }

    public timePicked(): boolean {

        if (this.time) {
            return true;
        } else {
            return false;
        }
    }

    public saveReminder(): void {

        if (this.timePicked()) {

            var scheduleDate = new Date(this.actualDate() + ' ' + this.time);

            LocalNotifications.schedule({
                id: 1,
                text: '¡Hora de meditar!',
                //at: new Date(new Date().getTime() + 5),
                at: scheduleDate,
                sound: 'file://audio/sound.mp3',
                every: "day",
                //data: { message : 'Informacion' },
                //icon: 'res://icon',
                //smallIcon: 'res://ic_popup_sync'
            });

            this.persistToggleStatus();
            this.persistTime();
            this.showSavedReminderMsg();
        } else {
            this.showNoTimePickedError();
            setTimeout(() => {
                this.toggleStatus = false;
            }, 100)
        }

    }

    public persistToggleStatus(): void {

        this.storage.set('reminderToggleStatus', this.toggleStatus);
    }

    public persistTime(): void {

        this.storage.set('reminderTime', this.time);
    }