In the previous few articles, we use {{}} to render the data, and we'll talk about it today.
<div ng-controller= "Aaa" >
<div>{{text}}</div>
</div>
<script type= "Text/javascript" >
alert (123);
Varm1 = Angular.module (' myApp ', []);
M1.controller (' Aaa ', [' $scope ', function ($scope) {
$scope. Text = ' XIECG ';
}]);
</script>
|
The problem is obvious, when we don't click OK, the following code is not executed, so also did not return to the status of {{text}}, assuming that the network bandwidth is very slow, the JS script has not loaded in, the page is all {{}} such symbols, obviously the user experience is obviously bad.
We use the Ng-bind directive to resolve this problem.
<div ng-controller= "Aaa" >
<div ng-bind= "Text" ></div>
</div>
<script type= "Text/javascript" >
Alert (123)
Varm1 = Angular.module (' myApp ', []);
M1.controller (' Aaa ', [' $scope ', function ($scope) {
$scope. Text = ' XIECG ';
}]);
</script>
|
Isn't it great? The problem here, there is not only a text data, there are many, how to write it?
<div ng-controller= "Aaa" >
<div ng-bind-template= ' {text}},{{text}} ' ></div>
</div>
<script type= "Text/javascript" >
Varm1 = Angular.module (' myApp ', []);
M1.controller (' Aaa ', [' $scope ', function ($scope) {
$scope. Text = ' XIECG ';
}]);
</script>
|
Ng-bind-template= ' {{text}},{{text}} ' multiple forms
Ng-bind= a single expression of "text"
Read the above introduction, if you still feel that the expression on the label is uncomfortable to be solved by ng-cloak ...
<div ng-controller= "Aaa" >
<div ng-cloak>{{text}}</div> Ng-cloak is none before rendering, block after rendering ends
</div>
<script type= "Text/javascript" >
alert (123);
Varm1 = Angular.module (' myApp ', []);
M1.controller (' Aaa ', [' $scope ', function ($scope) {
$scope. Text = ' XIECG ';
}]);
</script>
|
The Ng-cloak is none before rendering, and the block after rendering ends.
Also add that when angular is introduced, a CSS style is embedded in the header.
Let's say the back end gives us a piece of text that contains the {{}} symbols that can be ng-non-bindable to mask angular parsing.
<div ng-controller= "Aaa" >
<div ng-non-bindable>{{text}}</div>
</div>
<script type= "Text/javascript" >
Varm1 = Angular.module (' myApp ', []);
M1.controller (' Aaa ', [' $scope ', function ($scope) {
$scope. Text = ' XIECG ';
}]);
</script>
|
If it is a section of HTML code, want to parse the words need to introduce plug-ins ...
Complete code:
<metahttp-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Data display optimization processing </title>
<scripttype= "Text/javascript" src= "Https://code.angularjs.org/1.3.8/angular.min.js" ></script>
<scripttype= "Text/javascript" src= "Http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular-sanitize.min.js" ></script>
<divng-controller= "Aaa" >
<divng-bind-html= "HTML" ></div>
<scripttype= "Text/javascript" >
var m1 = angular.module (' myApp ', [' ngsanitize ']); The introduction of angular plug-ins requires modules that rely on Plug-ins in the module
M1.controller (' Aaa ', [' $scope ', function ($scope) {
|
Here's how to handle styles and attributes in angular.
Style:
<div ng-class= "{red:true,yellow:true}" >{{text}}</div>
<div ng-controller= "Aaa" >
<div ng-style= "{{style}}" >{{text}}</div>
</div>
<script type= "Text/javascript" >
Varm1 = Angular.module (' myApp ', []);
M1.controller (' Aaa ', [' $scope ', function ($scope) {
$scope. Text = ' XIECG ';
Object-type data can also be rendered as inline styles
$scope. style = {
Color: ' Red ',
Background: ' Blue '
};
}]);
</script>
|
Property:
<div ng-controller= "Aaa" >
<a ng-href= "{{URL}}" >baidu</a>
<a ng-attr-href= ' {{URL}} ' ng-attr-title= ' {{text}} ' >baidu</a>
</div>
<script type= "Text/javascript" > /div>
varm1 = angular.module (' myApp ', []);
m1.controller (' Aaa ', [' $scope ', function ($scope) {
&NB SP; $scope. Text = ' XIECG ';
$scope. url = ' https://www.baidu.com/';
}];
</script>
|
A
Custom attribute can be written in such a form as ng-attr-**.