代码下载:https://files.cnblogs.com/files/xiandedanteng/angularjsAttenSpan.rar
AngularJS中,<span class="bluetext" ng-bind="ctrl.user.name|uppercase"></span>和{{ctrl.user.name|uppercase}}是等价的,但不等于<span class="bluetext" ng-bind="ctrl.user.name|uppercase"/>,这样写会让/>后面的文字失效,如下图:
页面代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html ng-app="notesApp"> <head> <title> New Document </title> <style> .bluetext{ color:lightblue; } </style> <meta charset="gbk"> <script src="angular1.4.6.min.js"></script> </head> <body ng-controller="MainCtrl as ctrl"> <p>Hi,I am <span class="bluetext" ng-bind="ctrl.user.name|uppercase"></span> from China</p> <p>Hi,I am <span class="bluetext" ng-bind="ctrl.user.name|uppercase"/> from China</p> <p>Hi,I am <span class="bluetext">{{ctrl.user.name|uppercase}}</span> from China</p> </body> </html> <script type="text/javascript"> <!-- angular.module('notesApp',[]) .controller('MainCtrl',[function(){ var self=this; self.user={name:"Andy Liu"}; }]); //--> </script>