Angular.js模板内容的闪存

Quo*_*ent 7 angularjs

我有一个相当简单的页面,它调用2个静态json文件来填充它以及我在FF和chrome中注意到的内容如果我看起来很快就是我在页面中看到运行时的标签然后它们会在一秒后更新(字面意思) 500毫秒后)

这是一段简短的视频.

http://screencast.com/t/RZhEIxKj5

这是瀑布的样子

http://screencast.com/t/Be3JvLIYK00P

这是控制器的样子

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";
        }             
    }); 
}
Run Code Online (Sandbox Code Playgroud)

这就是我的json的样子

[
    {
        "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"
    }
]
Run Code Online (Sandbox Code Playgroud)

Vla*_*kov 11

使用ng-cloak类来控制此闪光灯.查看详细帮助ins angular的常见问题解答页面 - http://docs.angularjs.org/api/ng.directive:ngCloak

在模板中:

<div ng-app class="ng-cloak">
    …
</div>
Run Code Online (Sandbox Code Playgroud)

在CSS中:

.ng-cloak {
    opacity: 0;
}
Run Code Online (Sandbox Code Playgroud)