我们不能templateUrl
在当前的稳定版本(1.0.8)中将函数归因于,所以这就是我所做的。
HTML
<div ng-controller="MainCtrl">
<div class="genericDirective" ng-repeat="obj in someArray"></div>
</div>
Javascript
var app = angular.module("myApp", []);
app.controller("MainCtrl", function ($scope) {
$scope.someArray = [
{type:"type1",title:"lorem"},
{type:"type2",title:"ipsum"},
{type:"type2",title:"dolor"}
];
});
app.directive("genericDirective", function(){
return{
restrict: "C",
templateUrl: "genericDirective.html"
};
});
genericDirective.html
<div ng-include="thumb.type+'Thumb.html'"></div>
由于某种原因,我没有设法嵌套指令,所以我ng-include
改用了。(编辑:问题在这里解决)