Reputation: 8640
Is there a way to prevent flicker for templates that contain concatenated values such as {{person.LastName+ ", " + person.FirstName}}
?
I don't want to see the "," until $scope.person
is bound.
Is this something that I might put into a filter? Would you create a filter for something this trivial?
Upvotes: 8
Views: 13334
Reputation: 13306
Had some issues with ng-cloak so i resorted to using plain old css:
<div class="digits" style="display:none;">
And on the controller:
document.querySelector('.digits').style.display = 'block';
Upvotes: 0
Reputation: 388
You can use "ng-bind" attribute in your wrapper tag so instead of this:
<span>{{person.LastName+ ", " + person.FirstName}}</span>
You can do this:
<span ng-bind="person.LastName + ', ' + person.FirstName"></span>
This will change the tag text only when the value is properly concatenated.
Upvotes: 5
Reputation: 9416
This happens because you're loading your angular js lib not from the <head></head>
section. If it's not a big deal to you, just move your angular <script>
tag in the head and it should stop flickering.
Upvotes: -1
Reputation: 3444
You can simply use ng-show
for this.
I've created a demo to show the results.
http://plnkr.co/edit/ZAC8RzagPYmLHgXcPazW?p=preview
I'm using a timeout of 2 seconds in the controller so you can see the flicker if you remove ng-show.
Upvotes: 6
Reputation: 4603
You can use the ngCloak directive for that. From the docs:
The ngCloak directive is used to prevent the Angular html template from being briefly displayed by the browser in its raw (uncompiled) form while your application is loading. Use this directive to avoid the undesirable flicker effect caused by the html template display.
Upvotes: 14