17

I have a link. When user will click in this link, then the page will be reloaded. I did it by the following way......

Html

<div data-ng-hide="backHide" class="offset6 pull-right">
     <a href="" data-ng-click="backLinkClick()"><< Back  <br/> <br/></a>
 </div>

JS

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

In the controller I have used javascript and that seems to me very bad. How can I do it using angularjs

Atish Dipongkor
  • 9,710
  • 8
  • 47
  • 76

4 Answers4

35

Be sure to include the $route service into your scope and do this:

$route.reload();

See this:

How to reload or re-render the entire page using AngularJS

Community
  • 1
  • 1
Scalpweb
  • 1,951
  • 1
  • 11
  • 14
  • 2
    I sometimes have to recompile the page without reloading it (e.g. I have a special way of localizing it). Then I just call `$compile(angular.element('whatever div wrapping ng-view')(scope))` – Eduard Gamonal Sep 13 '13 at 07:41
7

You can also try this, after injecting $window service.

$window.location.reload();
justnajm
  • 4,045
  • 6
  • 33
  • 55
3

You need $route defined in your module and change the JS to this.

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

that works fine for me.

Preview
  • 34,540
  • 10
  • 86
  • 108
  • 2
    Why so many negative? Any arguments? I understand using this is a bad idea, but just downvote and don't describe why is not better. – alexche8 Dec 30 '14 at 15:37
  • 1
    @alexche8 There many things wrong with post. First the users says you need $route defined in your module than goes and totally ignores it himself by using window.location.reload which is till an other bad practice in angular apps(use $window wrapper instead of window otherwise your breaking angular abstraction). user2975967 is suggestion a bad but working solution. – Dynamikus Jan 23 '15 at 02:55
0
$scope.rtGo = function(){
            $window.sessionStorage.removeItem('message');
            $window.sessionStorage.removeItem('status');
        }