角度重新加载窗口,然后进入新状态 [英] Angular reload window then go to a new state

查看:136
本文介绍了角度重新加载窗口,然后进入新状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a large angular app with many forms for many items.

我有动作对象列表.

这些动作具有模式形式.

These actions have schemaforms.

这些动作形式的下拉菜单与一个动作与另一个动作不同. (下拉菜单的内容取决于该操作是哪个公司的子公司)

These actions form's dropdown's differ from one action to the next. (the dropdown's contents depends on which company the action is a child of)

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

These dropdowns contents were not changing unless I reloaded the page.

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

How do I do a window reload then a state.go change?

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

当前问题:

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

Current problem:

This code is supposed to clear the older schema from the cookies/local storage/etc so that the dropdowns show the current action's dropdown contents not the last action's dropdown contents. Then take you to the new action's page.

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

This code, instead, takes the user to the actionWizard page, then takes them back to the company page.

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

I am loading the dropdown contents from a file called sharedVars here:

.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

整个表单的HTML:

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

编辑3

我的bower.json看起来像:

EDIT 3

my bower.json looks like:

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

So, I do not have ngRoute, but I do have angular-ui-router

我尝试使用$ state重新加载,但是下拉列表仍然无法有效地重新加载.因此,此处的第一行似乎没有任何作用.

I have attempted to reload using $state but the dropdown still does not reload effectively. So, the 1st line here seems to have no effect.

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

编辑5

这也不起作用:

EDIT 5

This also does not work:

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

编辑6

我在这里提出了一个新的问题,我相信它已经接近问题的核心:推荐答案

此答案仅在进入操作页面时使用$window进行reload.但是避免使用散列进行递归.

This answer only uses $window to do a reload upon entering the action page. But avoids recursion by using a hash.

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

下面的更多说明

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

This code enables a full reload after a redirect. It is run upon entering the new page.

第一次访问,URL不包含刷新",因此$window.location.href更改为包含刷新".但是不会重新加载页面.只有重新加载页面并清除缓存后的行.但是,重新加载仅在添加哈希之后发生.

First time through, the url does not contain 'refresh', so $window.location.href changes to contain 'refresh'. BUT this does not reload the page. Only the line after it reloads the page and clears the cache. But, the reload only happened after the hash was added.

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

So, I engaged in a full reload without an infinite loop that happens automatically upon entering the page

这篇关于角度重新加载窗口,然后进入新状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆