AngularJS Button to reload state does not work

可紊 提交于 2019-12-25 14:14:19

问题


I want to have a button on the front end (AngularJS) that refreshes the changes made to the database. I have tried the following in the html:

<button ng-click="reloadState" data-translate> Refresh Database </button>

In the app.js file, I have this function in my controller:

$scope.reloadState = function() {
   $state.go($state.current, {}, {reload: true});
}

I have also tried:

$scope.reloadState = function() {
    $state.reload();
};

and:

$scope.reloadState = function() {
    window.location.reload();
}

Why does nothing happen when I click the button? Ps. I am using ui-router.


回答1:


Try $state.transitionTo($state.current, {}, {reload: true})




回答2:


The simplest way to do this is traditional Javascript by using location.reload();

http://www.w3schools.com/jsref/met_loc_reload.asp



来源:https://stackoverflow.com/questions/31363435/angularjs-button-to-reload-state-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!