source

현재 상태를 새로고침하려면 어떻게 해야 합니까?

nicesource 2023. 3. 5. 09:54
반응형

현재 상태를 새로고침하려면 어떻게 해야 합니까?

Angular UI 라우터를 사용하고 있으며 현재 상태를 다시 로드하고 모든 데이터를 새로 고치거나 현재 상태와 상위 상태의 컨트롤러를 다시 실행합니다.

상태 레벨은 directory.organizations.details의 3가지입니다.

directory.organizations에는 조직의 목록이 있는 테이블이 포함되어 있습니다.테이블의 항목을 클릭하면 directory.organizations.details가 로드되고 $StateParams는 해당 항목의 ID를 전달합니다.따라서 Details 상태에서 이 항목에 대한 세부 정보를 로드하고 편집한 다음 데이터를 저장합니다.아직까지는 괜찮아.

이제 이 상태를 새로고침하고 모든 데이터를 새로 고쳐야 합니다.

시도했습니다.

 $state.transitionTo('directory.organisations');

경로가 변경되지 않았기 때문에 컨트롤러는 새로고침되지 않습니다.이상적으로는 directory.organizations.details 상태를 유지하고 부모 데이터도 모두 새로 고치고 싶습니다.

나도 시도해봤어:

$state.reload()

API Wiki에서 $state.reload(컨트롤러가 재설치되어 곧 수정되는 오류)에 대해 본 적이 있습니다.

도움이 필요하신가요?

이것이 UI 라우터를 사용하여 새로 고치는 가장 빠른 방법임을 알게 되었습니다.

$state.go($state.current, {}, {reload: true}); //second parameter is for $stateParams

최신 버전 업데이트:

$state.reload();

다음 에일리어스입니다.

$state.transitionTo($state.current, $stateParams, { 
  reload: true, inherit: false, notify: true
});

문서: https://angular-ui.github.io/ui-router/site/ # / api / ui . _statestate state . $state # __reloadreload_displays

이 솔루션은 AngularJS V.1.2.2에서 동작합니다.

$state.transitionTo($state.current, $stateParams, {
    reload: true,
    inherit: false,
    notify: true
});

그것이 최종 해결책입니다.(@Hollan_Risley 게시물에서 영감을 얻음)

'use strict';

angular.module('app')

.config(function($provide) {
    $provide.decorator('$state', function($delegate, $stateParams) {
        $delegate.forceReload = function() {
            return $delegate.go($delegate.current, $stateParams, {
                reload: true,
                inherit: false,
                notify: true
            });
        };
        return $delegate;
    });
});

새로고침이 필요한 경우 언제든지 다음 번호로 전화하십시오.

$state.forceReload();

이온 프레임워크용

$state.transitionTo($state.current, $state.$current.params, { reload: true, inherit: true, notify: true });//reload

$stateProvider.
  state('home', {
    url: '/',
    cache: false, //required

https://github.com/angular-ui/ui-router/issues/582

아마 더 깨끗한 접근방식은 다음과 같습니다.

<a data-ui-sref="directory.organisations.details" data-ui-sref-opts="{reload: true}">Details State</a>

상태를 새로고침할 수 있는 것은 HTML 뿐입니다.

@Holland Risley의 답변은 최신 ui-router에서 API로 이용할 수 있게 되었습니다.

$state.reload();

현재 상태를 강제로 새로고침하는 방식입니다.모든 해결이 다시 해결되고 컨트롤러가 다시 설치되며 이벤트가 다시 실행됩니다.

http://angular-ui.github.io/ui-router/site/ # / api / ui . http . state . $ state .

$state.go($state.current, $stateParams, {reload: true, inherit: false});
$scope.reloadstat = function () { $state.go($state.current, {}, {reload: true}); };

페이지 전체를 새로고침하고 싶다면 컨트롤러에 $120을 삽입하고 콜을 클릭합니다.

$window.location.href = '/';

그러나 현재 뷰만 새로고침하는 경우 $scope, $state 및 $stateParams(다음 새로고침에서 페이지 번호 등 파라미터를 변경해야 할 경우를 대비해서 후자)를 삽입하고 컨트롤러 방식 내에서 호출합니다.

$stateParams.page = 1;
$state.reload();

AngularJS v1.3.15 Angular-ui-router v0.2.15

항상 효과가 있는 바보 같은 회피책.

$state.go("otherState").then(function(){
     $state.go("wantedState")
});

각도 v1.2.26의 경우 위의 어느 것도 동작하지 않습니다.위의 메서드를 호출하는ng-click은 상태를 새로고침하기 위해 번 클릭해야 합니다.

그래서 $timeout을 사용하여 클릭 2개를 에뮬레이트했습니다.

$provide.decorator('$state',
        ["$delegate", "$stateParams", '$timeout', function ($delegate, $stateParams, $timeout) {
            $delegate.forceReload = function () {
                var reload = function () {
                    $delegate.transitionTo($delegate.current, angular.copy($stateParams), {
                        reload: true,
                        inherit: true,
                        notify: true
                    })
                };
                reload();
                $timeout(reload, 100);
            };
            return $delegate;
        }]);

나는 모든 것이 실패했다.유일하게 효과가 있는 것은 cache-view="false"를 새로고침할 뷰에 추가하는 것입니다.

이 호부터 https://github.com/angular-ui/ui-router/issues/582

왜 이 중 어느 것도 나에게 효과가 없는 것 같았는지 모르겠다. 결국 그렇게 된 것은 다음과 같다.

$state.reload($state.current.name);

이것은 Angular 1.4.0의 경우입니다.

중첩된 뷰가 여러 개 있었는데, 목표는 한 개만 컨텐츠로 다시 로드하는 것이었습니다.여러 가지 방법을 시도했지만 효과가 있었던 유일한 방법은 다음과 같습니다.

//to reload
$stateParams.reload = !$stateParams.reload; //flip value of reload param
$state.go($state.current, $stateParams);

//state config
$stateProvider
  .state('app.dashboard', {
    url: '/',
    templateUrl: 'app/components/dashboard/dashboard.tmpl.html',
    controller: 'DashboardController',
    controllerAs: 'vm',
    params: {reload: false} //add reload param to a view you want to reload
  });

이 경우 필요한 뷰만 새로고침되고 캐시는 계속 작동합니다.

많은 답변이 있었지만 페이지 전체를 새로 고치지 않고 이 작업을 수행할 수 있는 최선의 방법은 새로고침하는 경로에 더미 파라미터를 작성하고 경로를 호출할 때 더미 파라미터에 난수를 전달합니다.

            .state("coverage.check.response", {
                params: { coverageResponse: null, coverageResponseId: 0, updater: 1 },
                views: {
                    "coverageResponse": {
                        templateUrl: "/Scripts/app/coverage/templates/coverageResponse.html",
                        controller: "coverageResponseController",
                        controllerAs: "vm"
                    }
                }
            })

그리고 그 루트로의 콜은

$state.go("coverage.check.response", { coverageResponse: coverage, updater: Math.floor(Math.random() * 100000) + 1 });

마법처럼 작동하며 해결 방법을 처리합니다.

@Rohan answer https://stackoverflow.com/a/23609343/3297761 를 사용할 수 있습니다.

그러나 뷰 변경 후 각 컨트롤러를 다시 로드하려면

myApp.config(function($ionicConfigProvider) { $ionicConfigProvider.views.maxCache(0); ... }

ionic v1을 사용하는 경우 ionic이 $ionic Config Provider의 일부로 템플릿 캐시를 사용하도록 설정했기 때문에 위의 솔루션은 작동하지 않습니다.

이 문제를 해결하려면 ionic.angular.js 파일에서 캐시를 0으로 설정해야 합니다.

$ionicConfigProvider.views.maxCache(0);

내 머리를 망가뜨리는 문제가 있었는데, 내 라우팅이 JSON 파일에서 읽혀져 지시어로 보내진다.UI 상태를 클릭할 수는 있지만 페이지를 다시 로드할 수 없습니다.그래서 내 동료가 멋진 묘기를 보여줬어

  1. 데이터 가져오기
  2. 앱 구성에서 로드 상태를 만듭니다.
  3. 이동할 상태를 루트 스코프에 저장합니다.
  4. app.run에서 위치를 "/loading"으로 설정합니다.
  5. 로딩 컨트롤러에서 라우팅 약속을 해결한 후 원하는 타겟으로 위치를 설정합니다.

이건 나한테 효과가 있었어.

도움이 되었으면 좋겠다

언급URL : https://stackoverflow.com/questions/21714655/how-to-reload-the-current-state

반응형