현재 상태를 다시로드하는 방법?
Angular UI Router를 사용하고 있으며 현재 상태를 다시로드하고 모든 데이터를 새로 고치거나 현재 상태 및 상위에 대한 컨트롤러를 다시 실행하고 싶습니다.
나는 3 가지 상태 수준이 있습니다 : directory.organisations.details
directory.organisations 에는 조직 목록이 포함 된 테이블이 있습니다. 테이블로드의 항목을 클릭 directory.organisations.details 항목의 ID를 전달 $ StateParams와. 세부 정보 상태 에서이 항목의 세부 정보를로드하고 편집 한 다음 데이터를 저장합니다. 지금까지는 괜찮 았습니다.
이제이 상태를 다시로드하고 모든 데이터를 새로 고쳐야합니다.
나는 시도했다 :
$state.transitionTo('directory.organisations');
부모 상태로 이동하지만 컨트롤러를 다시로드하지 않는 경로는 변경되지 않았기 때문입니다. 이상적으로는 directory.organisations.details 상태 를 유지 하고 부모의 모든 데이터를 새로 고치기를 원합니다 .
나는 또한 시도했다 :
$state.reload()
나는 $ state.reload에 대한 API WIKI에서 이것을 보았습니다.
도움이 필요하십니까?
나는 이것이 ui-router로 새로 고치는 가장 짧은 작업 방법이라는 것을 알았습니다.
$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.router.state.$state#methods_reload
이 솔루션은 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 라우터에서 API로 사용할 수 있습니다.
$state.reload();
현재 상태를 강제로 다시로드하는 방법입니다. 모든 해결이 다시 해결되고 컨트롤러가 다시 인스턴스화되며 이벤트가 다시 발생합니다.
http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$state
$state.go($state.current, $stateParams, {reload: true, inherit: false});
$scope.reloadstat = function () { $state.go($state.current, {}, {reload: true}); };
보이는 것처럼 전체 페이지를 다시로드하려면 컨트롤러에 $ window를 삽입하고 호출하십시오.
$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을 사용하여 두 번의 클릭을 모방했습니다.
$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이 $ ionicConfigProvider의 일부로 템플릿 캐싱을 활성화했기 때문에 위의 솔루션이 작동하지 않습니다.
그 문제는 약간 해키입니다. ionic.angular.js 파일에서 캐시를 0으로 설정해야합니다.
$ionicConfigProvider.views.maxCache(0);
나는이 문제를 겪어 머리를 부수고 내 JSON 파일에서 라우팅을 읽은 다음 지시문에 넣었습니다. ui-state를 클릭 할 수 있지만 페이지를 다시로드 할 수 없습니다. 그래서 내 동료가 나에게 멋진 작은 트릭을 보여주었습니다.
- 데이터 가져 오기
- 앱 구성에서 로딩 상태를 만듭니다.
- 루트 스코프에서 가고자하는 상태를 저장하십시오.
- app.run에서 위치를 "/ loading"으로 설정하십시오.
- 로딩 컨트롤러에서 라우팅 약속을 해결하고 원하는 대상 위치를 설정하십시오.
이것은 나를 위해 일했습니다.
그것이 도움이되기를 바랍니다.
참고 URL : https://stackoverflow.com/questions/21714655/how-to-reload-the-current-state
'Programing' 카테고리의 다른 글
LaTeX에서 변수를 정의 할 수있는 방법이 있습니까? (0) | 2020.03.08 |
---|---|
특성과 인터페이스 (0) | 2020.03.07 |
안드로이드-실행기 아이콘 크기 (0) | 2020.03.07 |
Docker 공유 볼륨에 대한 권한을 관리하는 가장 좋은 방법은 무엇입니까? (0) | 2020.03.07 |
해시 함수가 소수 모듈을 사용해야하는 이유는 무엇입니까? (0) | 2020.03.07 |