0

背景

我有一个大型角度应用程序,其中包含许多项目的多种形式。

我有动作对象列表。

这些动作有模式。

这些操作表单的下拉菜单因一项操作而异。(下拉列表的内容取决于该操作是哪个公司的子项)

除非我重新加载页面,否则这些下拉列表内容不会改变。

问题

如何重新加载窗口然后更改 state.go?

代码

  $scope.goToActionWizardFull = function(CUuid, AUuid) {
    $window.location.reload();
    $state.go('actionWizard', { companyUuid: CUuid, uuid: AUuid });
  }

当前问题:

此代码应该从 cookie/本地存储/等中清除旧模式,以便下拉菜单显示当前操作的下拉内容,而不是最后一个操作的下拉内容。然后将您带到新操作的页面。

相反,此代码将用户带到 actionWizard 页面,然后将他们带回公司页面。

额外的上下文

我在这里从一个名为 sharedVars 的文件中加载下拉内容:

.controller('ActionController', function ($scope, $stateParams, $state, $window, sharedVars, Company, Action) {

我在这里加载它:

$scope.actionSchema = sharedVars.getActionSchema();

然后在这里改变它:

$scope.actionSchema.properties.RDAInput.items.properties.input_location.enum = $scope.actionSchema.properties.RDAInput.items.properties.input_location.enum.concat(eachRDSchemaProperty['name'])

然后我加载表格。

这一切都在http://schemaform.io

编辑 2

整个表单的 HTML:

<form sf-schema="actionSchema" sf-form="actionForm" sf-model="actionModel" name="submittableActionForm">
</form>

编辑 3

我的 bower.json 看起来像:

{
  "name": "isp",
  "appPath": "src/main/web",
  "moduleName": "ispApp",
  "version": "0.0.1",
  "dependencies": {
    "jquery": "2.1.1",
    "angular": "1.6.1",
    "json3": "3.3.2",
    "angular-ui-router": "0.4.1",
    "angular-resource": "1.6.1",
    "angular-sanitize": "1.6.1",
    "checklist-model": "0.10.0",
    "jsog": "1.0.7",
    "angular-schema-form": "^0.8.13",
    "angular-schema-form-bootstrap": "^0.2.0",
    "bootstrap": "3.3.7",
    "angular-cookies": "1.6.1"
  },
  "resolutions": {
    "angular": "1.6.9"
  },
  "install": {
    "path": "src/main/web/bower_components"
  }
}

所以,我没有 ngRoute,但我有 angular-ui-router

编辑 4

我尝试使用 $state 重新加载,但下拉列表仍然无法有效地重新加载。所以,这里的第一行似乎没有效果。

$state.go($state.current, {}, {reload: true});
$state.go('actionWizard', { companyUuid: CUuid, uuid: AUuid });

编辑 5

这也不起作用:

$state.transitionTo($state.current, $stateParams, {
reload: true,
inherit: false,
notify: true
}) 
$state.go('actionWizard', { companyUuid: CUuid, uuid: AUuid });

编辑 6

我在这里提出了一个新问题,我相信它更接近问题的核心:重新加载页面缓存,然后转到新页面

4

1 回答 1

0

此答案仅用于$windowreload进入操作页面时执行。但是通过使用哈希来避免递归。

    var currentHref = $window.location.href
    if (!currentHref.includes("refresh")) {
        $window.location.href = $window.location.href + "#refresh"
        $window.location.reload(true);
    }

下面有更多解释

此代码在重定向后启用完全重新加载。它在进入新页面时运行。

第一次通过时,网址不包含“刷新”,因此$window.location.href更改为包含“刷新”。但这不会重新加载页面。只有在它重新加载页面并清除缓存之后的行。但是,重新加载仅在添加哈希之后发生。

因此,我进行了完全重新加载,没有在进入页面时自动发生的无限循环

于 2018-07-31T16:47:58.100 回答