繁体   English   中英

如果我离开页面并返回该页面,更改将消失-Ionic App

[英]Changes disappear if I navigate away from page and comeback to that page - Ionic App

在我的离子应用程序中,我有一个页面,可以在其中编辑和保存信息。 信息之一是图像。 要选择新图像,它可以导航到包含要选择图像的页面。

因此,如果用户更改某些其他文本字段然后尝试更改图像,则他必须离开页面导航以选择新图像。 但是一旦选择图像后他又回来了,所有其他更改都消失了,并且又回到了旧数据上。

我希望用户返回页面后其他信息仍然存在。

这是我当前的代码:

<div class="content content-top content-bottom">
            <ch-device-avatar ng-model="client" ch-size="xxlarge" ch-color="light"
                              ng-click="go(STATES.DEVICES_EDIT_ICON, {'macAddress': macAddress})">
                <ch-avatar ch-icon="ion-edit" ch-size="small" ch-color="positive"></ch-avatar>
            </ch-device-avatar>
        </div>

        <form id="client-form" class="form" name="forms.clientForm" ng-submit="save()" novalidate>
            <label class="item item-input item-floating-label" ch-input-container>
                <span class="input-label">{{ 'main.label-device-name' | i18n }}</span>
                <input type="text" name="name" placeholder="{{ 'main.label-device-name' | i18n }}" autocomplete="off"
                       ng-model="client['name']" ng-maxlength="64" required>
            </label>
            <div ng-messages="forms.clientForm.name.$error" role="alert" ch-messages="name" multiple>
                <div class="hint hint-error" ng-message="required">{{ 'common.error-required' | i18n }}</div>
                <div class="hint hint-error" ng-message="maxlength">{{ 'common.error-max-length' | i18n:'65' }}</div>
            </div>
        </form>

这是因为一旦您离开页面,这些组件就会被破坏。[默认的角度行为]

您可能需要利用Shared Services将信息保存到服务变量中,以便一旦返回就可以从中获取它们(如果它们不为空)。

您甚至可以使用像Firebase这样的实时数据库来解决此问题。

链接刷新

使用router-outlet,每次导航都会创建该组件的新实例,并在导航到另一个组件时将其销毁。 每次您导航到该组件时都会调用该组件的构造函数及其初始化挂钩,并且每次您离开该组件时都将调用ngOnDestroy()。

有关共享服务的更多信息链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM