【问题标题】:Changes disappear if I navigate away from page and comeback to that page - Ionic App如果我离开页面并返回该页面,更改就会消失 - Ionic App
【发布时间】:2017-08-01 17:22:12
【问题描述】:

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

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

我希望在用户返回页面后保留其他信息。

这是我当前的代码:

<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>

【问题讨论】:

    标签: javascript ionic-framework


    【解决方案1】:

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

    您可能需要使用共享服务将信息保存到服务变量中,以便您返回后可以从它们中获取(如果它们不为空)。

    对于这个解决方案,您甚至可以选择像 Firebase 这样的实时数据库。

    来自Link的引用

    使用 router-outlet 创建组件的新实例 每个导航并在您导航到另一个导航时被破坏 零件。组件的构造函数及其初始化钩子将是 每次导航到组件时调用,ngOnDestroy() 将 每次离开它时都会被调用。

    更多关于共享服务link

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-28
      • 2014-08-11
      • 2012-11-10
      • 2013-12-12
      • 2014-01-08
      相关资源
      最近更新 更多