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

9
  • 1
    If you are using routing you can do $route.reload(); Commented Sep 13, 2013 at 7:28
  • 1
    No, I am not using routing Commented Sep 13, 2013 at 7:29
  • I dont think not using angular is a bad idea here. Simply move your code inside onclick of <a tag: onclick="window.location.reload(false)" Commented Sep 13, 2013 at 7:38
  • 1
    if you have to use window you should use the wrapper: $window. however, $route.reload() is probably what you're looking for. Commented Sep 13, 2013 at 7:39
  • 3
    possible duplicate of How to reload or re-render the entire page using AngularJS Commented Feb 25, 2014 at 9:45

4 Answers 4

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

Sign up to request clarification or add additional context in comments.

1 Comment

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))
7

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

$window.location.reload();

1 Comment

I'm not using angular routing and this worked perfectly for me.
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.

2 Comments

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 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.
0
$scope.rtGo = function(){
            $window.sessionStorage.removeItem('message');
            $window.sessionStorage.removeItem('status');
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.