Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular.js flash of template content

Tags:

angularjs

I have a rather simple page, it calls 2 static json files to populate it and what i am noticing in FF and chrome if I look quick is that I see the tags at runtime in the page and then they are updated a second later (literally 500ms later)

here is a short video.

http://screencast.com/t/RZhEIxKj5

here is what the waterfall looks like

http://screencast.com/t/Be3JvLIYK00P

here is what the controller looks like

function HotelsController($scope, $http) {
  $http.get('data/hotels.json').then(function(res){
    $scope.hotels = res.data;                
    });
}


function ConfirmationsController($scope, $http) {
  $http.get('data/confirmations.json').then(function(res){
    $scope.confirmations =  res.data;
    if ($scope.confirmations.length > 0) {
        $scope.showConfirmations = "1";
        } 
    else {
        $scope.showConfirmations = "0";
        }             
    }); 
}

and here is what my json looks like

[
    {
        "nights": 2,
        "hotel": "Hotel McCormick Place",
        "confirmationNumber": "2345J453",
        "checkIn": "18-Dec",
        "checkOut": "20-Dec",
        "roomType": "King, None-Smoking"
    },
    {
        "nights": 1,
        "hotel": "ABC Inn",
        "confirmationNumber": "1234567",
        "checkIn": "20-Dec",
        "checkOut": "21-Dec",
        "roomType": "Standard, None-Smoking"
    }
]

[
    {
        "name": "Empire Hotels",
        "img": "http://placehold.it/96x64",
        "address": "123 Main Street, Texas"
    },
    {
        "name": "Lemon Tree Hotel",
        "img": "http://placehold.it/96x64",
        "address": "123 Main Street, Texas"
    },
    {
        "name": "Palm Fiber",
        "img": "http://placehold.it/96x64",
        "address": "123 Main Street, Texas"
    }
]
like image 969
Quotient Avatar asked Jun 11 '13 22:06

Quotient


1 Answers

Use ng-cloak class to control this flash. Check detail help ins angular's FAQ page — http://docs.angularjs.org/api/ng.directive:ngCloak

In template:

<div ng-app class="ng-cloak">
    …
</div>

In CSS:

.ng-cloak {
    opacity: 0;
}
like image 50
Vladimir Starkov Avatar answered Oct 20 '22 21:10

Vladimir Starkov