Re: [angular.js] How to force angular to rerender whole page?

6,905 views
Skip to first unread message

Oliver Batchelor

unread,
Jul 10, 2012, 11:34:18 AM7/10/12
to ang...@googlegroups.com
How are you using that logged in user information?

Perhaps you can make a small jsfiddle example to demonstrate.

One common gotcha a lot of people run into is if you update the model
from outside of angular (e.g. from a JQuery event), then you need to
use scope.$apply.

e.g.

scope.$apply(function()
{
scope.loggedInUser = "fred";
});

Cheers,
Oliver

On Tue, Jul 10, 2012 at 3:57 PM, Freewind <nowi...@gmail.com> wrote:
> I store the logged user info in $rootScope, and I will do some
> initialization depend on the information.
>
> When I visit a page without login, I can see some content, then I logged in
> the same page, the content should be changed, but those initialization code
> will be executed again.
>
> So I wonder if there is a way to force angular to rerender the whole page
> again? For now, I'm using `$window.location.reload()` to reload current
> page.
>
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/angular/-/CN7FI_O9YekJ.
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/angular?hl=en.

Renan T. Fernandes

unread,
Jul 10, 2012, 12:38:01 PM7/10/12
to ang...@googlegroups.com
what about this?

var myApp angular.module('myApp',[]);

//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});

function MyCtrl($rootScope$scope{
    function checkStatus({
        if($rootScope.user// logged
            $scope.message $http(...)// read some content from server
        else {
            $scope.message $http(...)// read some other content from server
        }
    }
    $scope.login function({
        $rootScope.user $http(...)// try login
        checkStatus();
    }
}



2012/7/10 Freewind <nowi...@gmail.com>
Thanks for your answer, I just created an demo: http://jsfiddle.net/Freewind/eshDc/

The basic idea is there has been some content will be retrieved only once, depends on the log status. If the user logged in later, that content won't be retrieve again, unless I put that code to a "init" method and call it again. Let angular rerender the page would be a simple solution.
> For more options, visit this group at
> http://groups.google.com/group/angular?hl=en.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/DBvNQ9ocJ2sJ.

To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.



--
Renan Fernandes(aka "ShadowBelmolve")

Eric Jain

unread,
Jul 13, 2012, 5:58:34 PM7/13/12
to ang...@googlegroups.com
On Fri, Jul 13, 2012 at 1:17 PM, Rick Richardson
<rick.ri...@gmail.com> wrote:
> I don't mean to sound flippant, but intelligently selecting content and
> displaying based on given conditions is far superior to re-rendering an
> entire page, disrupting and slowing the user experience.

Re-rendering the page would still be superior to reloading the
page--but it doesn't look like angular provides such an option?
Reply all
Reply to author
Forward
Message has been deleted
0 new messages