我有以下html(可以直接访问或通过ajax调用):
<section id="content" ng-controller="setTreeDataCtrl" get-subthemes>
<dl ng-repeat="subtheme in allSubthemes">
<dt>{{subtheme.Title}}</dt>
</dl>
然后我使用以下指令:
myApp.directive('getSubthemes', function() {
return function($scope, element, attrs) {
$scope.allSubthemes = [];
angular.forEach($scope.data.Themes, function(value, key) {
angular.forEach(value.SubThemes, function(value2, key2) {
$scope.allSubthemes.push({
'ThemeTitle': value.Title,
'ThemeUrlSlug': value.UrlSlug,
'Title': value2.Title,
'UrlSlug': value2.UrlSlug
});
});
});
}
});
$scope.allSubthemes 似乎没问题,但是 dl 没有被渲染。我可以看到一切都正确渲染,然后它又回到 {{subtheme.Title}},几乎就像它正在“未渲染”......关于我做错了什么的任何想法?
演示 jsFiddle:http: //jsfiddle.net/HMp3a/