[工作问题]angluarjs中页面初始化的时候会出现语法{{}}在页面中
| 
                         angluarjs中页面初始化的时候会出现语法{{}}在页面中问题,也即是页面闪烁问题。 1.ng-cloakng-cloak指令是angular的内置指令,它的作用是隐藏所有被它包含的元素: <div ng-cloak>
     <h1>Hello {{ name }}</h1>
    </div> 
Ng-cloak实现原理为一个directive,页面初始化是在DOM的heade增加一行CSS代码,如下: <pre class= “prettyprint linenums”>
          [ng:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak{
          Display:none ! important;
        }
        </pre>
        <pre class= “prettyprint linenums”>
          [ng:cloak],.x-ng-cloak{
          Display:none ! important;
        } 
        </pre> 
Angular将带有ng-cloak的元素设置为display:none. script type =”text/ng-template” id =”scenario.js-150”>
     
      It(‘should remove the template directive and css class',function(){
     
     Expect(element(‘.doc-example-live #template1').attr(‘ng-cloak'))
     
      not().toBeDefined();
     
       Expect(element(‘.doc-example-live #template2').attr(‘ng-cloak')).
     
    Not().toBeDefined();
     
    });
     
    </script>
     
    <script type =”text/ng-template” id =”scenario.js-150”>
      
      It(‘should remove the template directive and css class',function(){
      
     Expect(element(‘.doc-example-live #template1').attr(‘ng-cloak'))
      
      not().toBeDefined();
      
       Expect(element(‘.doc-example-live #template2').attr(‘ng-cloak')).
      
    Not().toBeDefined();
      
    });
      
    </script> 
2.ng-bindng-bind是angular里面另一个内置的用于操作绑定页面数据的指令。我们可以使用ng-bind代替{{ }}的形式绑定元素到页面上; 使用ng-bind替代{{ }}可以防止未被渲染的{{ }}就展示给用户了,使用ng-bind渲染的空元素替代{{ }}会显得友好很多。 上面的例子可以重写成下面那样,这样就可以防止页面出现{{ }}了 <div>
     <h1>Hello <span ng-bind="name"></span></h1>
    </div> 
参考地址:http://www.aspzz.cn/article/80523.htm (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!  | 
                  
