Is there a different way to hide a scope variable from showing while AngularJS is loading?

user3568783

I am using this way:

<div ng-cloak>{{ message.userName || message.text }}</div>

Is this the only / best way to ensure the user does not see the {{ }} when AngularJS is still loading ?

Michal Charemza

There are several ways to hide content before Angular has a chance to run

  • Put the content you want to hide in another template, and use ngInclude

    <div ng-include="'myPartialTemplate.html'"></div>
    

    If you don't actually want another request made to the server to fetch another file, there are a couple of ways, as explained in the $templateCache docs. There are tools to "compile" external HTML templates into JS to avoid having to do this manually, such as grunt-angular-templates.

  • Similar to ngInclude, if you put everything in custom directives, with its own template, then the template content won't be shown until Angular has had a chance to run.

    <my-directive></my-directive>
    

    With a definition of:

    app.directive('myDirective', function() {
      return {
        restrict: 'E',
        template: '<div>Content hidden until Angular loaded</div>'
      }
    });
    
  • ngBind as an alternative to {{}} blocks

    <div>Hello <span ng-bind="name"></span></div>
    
  • ngCloak as you have mentioned (in this list for completeness).

    <div ng-cloak>Content hidden until Angular compiled the template</div>
    

    But you must have certain styles loaded before the page is rendered by the browser, as explained in the ngCloak docs.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Is there a different way to hide a scope variable from showing while AngularJS is loading?

From Dev

Hide template while loading in AngularJS

From Dev

Hide template while loading in AngularJS

From Dev

Prevent images from loading in an AngularJS view if scope variable is empty

From Dev

AngularJS: pass variable from backend while loading a page

From Dev

Avoid a repeated scope variable in different controllers in AngularJS

From Dev

AngularJS $scope not showing value

From Dev

AngularJS - Get $scope variable from string

From Dev

Setting a scope variable from a directive with AngularJS

From Dev

AngularJS - Get $scope variable from string

From Dev

AngularJS $watch controller variable from a directive with scope

From Dev

Angularjs Showing Loading spinner

From Dev

AngularJS directive: Produce different HTML depending on $scope variable

From Dev

AngularJS - iframe not showing when loading its src from json file

From Dev

Take data in $scope of angularjs while taking data from django

From Dev

Scope variable not printing AngularJS

From Dev

Variable scope issue with AngularJS

From Dev

Scope variable not binding in AngularJS

From Dev

Dynamic scope variable in angularjs

From Dev

Showing AJAX loading bars in AngularJS

From Dev

how to get variable from different AngularJS file?

From Dev

$http and $scope variable not showing in template

From Dev

How to avoid AngularJS ui grid showing 'no-data' message while api is loading

From Dev

AngularJS variable not showing in html

From Dev

Accessing $scope variable from another method in the same controller Angularjs

From Dev

Access $scope in different controllers in AngularJS

From Dev

Scope of a variable ends in a while loop

From Dev

loading scope value into an array doesnt work in angularjs

From Dev

Hide iframe while it is loading subsequent content

Related Related

  1. 1

    Is there a different way to hide a scope variable from showing while AngularJS is loading?

  2. 2

    Hide template while loading in AngularJS

  3. 3

    Hide template while loading in AngularJS

  4. 4

    Prevent images from loading in an AngularJS view if scope variable is empty

  5. 5

    AngularJS: pass variable from backend while loading a page

  6. 6

    Avoid a repeated scope variable in different controllers in AngularJS

  7. 7

    AngularJS $scope not showing value

  8. 8

    AngularJS - Get $scope variable from string

  9. 9

    Setting a scope variable from a directive with AngularJS

  10. 10

    AngularJS - Get $scope variable from string

  11. 11

    AngularJS $watch controller variable from a directive with scope

  12. 12

    Angularjs Showing Loading spinner

  13. 13

    AngularJS directive: Produce different HTML depending on $scope variable

  14. 14

    AngularJS - iframe not showing when loading its src from json file

  15. 15

    Take data in $scope of angularjs while taking data from django

  16. 16

    Scope variable not printing AngularJS

  17. 17

    Variable scope issue with AngularJS

  18. 18

    Scope variable not binding in AngularJS

  19. 19

    Dynamic scope variable in angularjs

  20. 20

    Showing AJAX loading bars in AngularJS

  21. 21

    how to get variable from different AngularJS file?

  22. 22

    $http and $scope variable not showing in template

  23. 23

    How to avoid AngularJS ui grid showing 'no-data' message while api is loading

  24. 24

    AngularJS variable not showing in html

  25. 25

    Accessing $scope variable from another method in the same controller Angularjs

  26. 26

    Access $scope in different controllers in AngularJS

  27. 27

    Scope of a variable ends in a while loop

  28. 28

    loading scope value into an array doesnt work in angularjs

  29. 29

    Hide iframe while it is loading subsequent content

HotTag

Archive