angularJs中ng-cloak指令

来源:互联网 发布:天音复制软件 编辑:程序博客网 时间:2024/05/22 06:33

angularJs中ng-cloak指令,是为了防止用{{}}双花括号显示数据时会出现括号闪现的问题,ng-bind本身已经避免了这个问题,在引用{{}}之外写上ng-cloak即可。也可以像下面例子里一样,定义class为ng-cloak的display: none;之后再遇到ng-cloak后即显示。

<!doctype html><html lang="en"><head>    <meta charset="UTF-8"></head><style>    .ng-cloak{        display: none;    }</style><body ng-app="module" ng-cloak class="ng-cloak"><div ng-controller="ctrl">    {{name+'学习'}}     <hr>    {{user.username}}    <hr>    {{num*8}}    <hr>    <h3 ng-bind="name"></h3></div><script src="angular.min.js"></script><script>    var m = angular.module('module', []);    m.controller('ctrl', ['$scope', function ($scope) {        $scope.name = 'angular';        $scope.num = 2;        $scope.user = {'username': '泠泠在路上', 'url': 'http://blog.csdn.net/u012396955'};    }]);</script></body></html>
原创粉丝点击