我想呈现来自HTML字符串数组的HTML字符串,我对AngularJS颇为陌生,我试图遵循AngularJs网站的示例,但似乎我无法弄清楚正确的方法要做到这一点。AngularJS用ng-bind-html重复呈现数组中的HTML字符串?
为了更好的理解,我希望我解释一下自己,如果不是只是要求更多的澄清。非常感谢您的帮助。
HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-example62-production</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-sanitize.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="bindHtmlExample">
<div ng-controller="ExampleController">
<div ng-repeat="bit in myHTML">
<p ng-bind-html="bit"></p>
</div>
</div>
</body>
</html>
控制器
(function(angular) {
'use strict';
angular.module('bindHtmlExample', ['ngSanitize'])
.controller('ExampleController', ['$scope', function($scope) {
for (i=0; i<6; i++){
$scope.myHTML[i] =
'I am an <code>HTML</code>string with ' +
'<a href="#">links!</a> and other <em>stuff</em>';
}
}]);
})(window.angular);