最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Angular的数据显示优化处理解析
时间:2016-12-29 编辑:简简单单 来源:一聚教程网
前面的几篇文章中,我们通过{{}}来渲染数据,今天就来聊聊它。
{{text}} |
问题显而易见了,当我们没有点击确定的时候,下面的代码是不会执行的,所以也没回一直呈现{{text}}的状态,假设网络的带宽很慢的情况下,js脚本还没有加载进来,页面全是{{}}这样的符号,显然用户体验很显然是不好的。
我们利用ng-bind指令可解决此问题。
alert(123)
varm1 = angular.module('myApp',[]);
m1.controller('Aaa',['$scope',function($scope){
$scope.text ='xiecg';
}]);
|
是不是很棒 ? 问题来了,这里不单单只有一个text数据,有很多个,如何写呢?
varm1 = angular.module('myApp',[]);
m1.controller('Aaa',['$scope',function($scope){
$scope.text ='xiecg';
}]);
|
ng-bind-template="{{text}},{{text}}" 多个表单式
ng-bind="text" 单个表达式
看了上面的介绍,如果还是觉得在标签上写表达式不舒服可通过ng-cloak来解决。。。
{{text}} ng-cloak在渲染之前是为none的,渲染结束後block alert(123);
varm1 = angular.module('myApp',[]);
m1.controller('Aaa',['$scope',function($scope){
$scope.text ='xiecg';
}]);
|
ng-cloak在渲染之前是为none的,渲染结束後block。
还补充一点,在引入angular的时候,header中会嵌入一段css样式。
假设後端返回给我们一段文字,上面包含了{{}}这些符号,可通过ng-non-bindable来屏蔽angular解析。
{{text}} varm1 = angular.module('myApp',[]);
m1.controller('Aaa',['$scope',function($scope){
$scope.text ='xiecg';
}]);
|
如果是一段html代码,想解析的话就需要引入插件。。。
完整代码:
var m1 = angular.module('myApp',['ngSanitize']); //引入angular插件,需要在模块依赖插件的模块
m1.controller('Aaa',['$scope',function($scope){
$scope.html = '
xiecg'; }]);
|