2015/09/07

AngularJS ng-bind-html

ng-bind-html可以將HTML程式碼透過AngularJS來印出

<!DOCTYPE html>
<html ng-app="myApp">
 <head>
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
  <!--必須加入這行-->
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-sanitize.js"></script>  
  <script type="text/javascript">
   var myApp = angular.module('myApp', ['ngSanitize']);
   myApp.controller('myController', function($scope){
    $scope.myHTML = '<br><b>hi<b></br>';
   });
  </script>
  <meta charset="utf8"/>
  <title>ng-bind-html</title>
 </head>
 <body>
  <div ng-controller="myController">
   <p ng-bind-html="myHTML"></p>
  </div>
 </body>
</html>



操作結果: