------- ---------的index.html
<head >
<script data-require="[email protected]" data-semver="1.3.0-beta.5" src="https://code.angularjs.org/1.3.0-beta.5/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body >
<div ng-controller="MyController">
<button ng-click="include('temp1.html')">Block 1</button><i ng-click="delete('temp1.html')">DEL 1</i>
<button ng-click="include('temp2.html')">Block 2</button><i ng-click="delete('temp2.html')">DEL 2</i>
<button ng-click="include('temp3.html')">Block 3</button><i ng-click="delete('temp3.html')">DEL 3</i>
<div ng-repeat="template in templates">
<div ng-include="template.url">Content from blocks goes here</div>
</div>
</div>
</body>
</html>
------- templ.html -----
<div>
This is template 1
</div>
------- temp2.html -----
<div>
This is template 2
</div>
- ---- TEMPL。HTML ------
<div>
This is template 3
</div>
-------- ---------- JS
angular.module("app", [])
.controller("MyController", function ($scope) {
$scope.templates=[];
$scope.include = function(templateURI) {
var template={url:templateURI};
$scope.templates.push(template);
}
$scope.delete= function(url){
removeEntity($scope.templates,url);
}
var removeEntity = function(elements,url){
elements.forEach(function(element,index){
if(element.url===url){
elements.splice(index,1);
removeEntity(elements,url);
}
})
}});
來源
2014-06-13 16:17:49
Tek
可能會考慮使用一個指令,並使用templateUrl功能設置動態網址 – charlietfl