另一种方式:
索引.html:
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<script data-require="angular.js@1.2.0" data-semver="1.2.0" src="http://code.angularjs.org/1.2.0/angular.min.js"></script>
<script data-require="angular-sanitize@*" data-semver="1.1.5" src="http://code.angularjs.org/1.1.5/angular-sanitize.min.js"></script>
<style>
.ac {
background-color: yellow;
}
.bc {
background-color: orange;
}
</style>
<script>
var app = angular.module('plunker', ['ngSanitize']);
app.controller('MainCtrl', function($scope) {
$scope.items = [{
"type": "A",
"url": "item_A.html",
"content": "<div class=\"ac\">content A</div>"
}, {
"type": "B",
"url": "item_B.html",
"content": "<div class=\"bc\">content B</div>"
}]
});
</script>
</head>
<body ng-controller="MainCtrl">
<div ng-repeat="item in items">
<div ng-switch on="item.type">
<div ng-switch-when="A">
<div ng-include="item.url"></div>
</div>
<div ng-switch-when="B">
<div ng-include="item.url"></div>
</div>
</div>
</div>
</body>
</html>
item_A.html:
Item A:
<div ng-bind-html="item.content"></div>
item_B.html:
Item B:
<div ng-bind-html="item.content"></div>
Plunker 示例