如何在没有ng-include的情况下使用Angular 2进行递归模板。我不明白为什么Angular 2不会包含这项技能......
HTML:
static func getFileNoCache(url:NSURL?, completionHandler:(NSData?, String?)->Void) {
if let fileUrl = url {
let request = NSURLRequest(URL: fileUrl, cachePolicy: .ReloadIgnoringCacheData, timeoutInterval: 5)
let dataTask = NSURLSession.sharedSession().dataTaskWithRequest(request,
completionHandler: { data, response, error in
if let err = error {
// failed !
print("!! Error - Download Failed \n\t\(fileUrl) reason:\(err.localizedDescription)")
completionHandler (nil, err.localizedDescription)
return
}
if let statusCode = (response as? NSHTTPURLResponse)?.statusCode {
if statusCode == 200 {
completionHandler(data, nil)
}
else {
completionHandler (nil, "Message")
}
}
else {
completionHandler (nil, "Invalid response")
print("!! Error - Downloading EPG Config")
}
})
dataTask.resume()
}
}
JS:
<div ng-app="app" ng-controller='AppCtrl'>
<script type="text/ng-template" id="categoryTree">
{{ category.title }}
<ul ng-if="category.categories">
<li ng-repeat="category in category.categories" ng-include="'categoryTree'">
</li>
</ul>
</script>
<ul>
<li ng-repeat="category in categories" ng-include="'categoryTree'"></li>
</ul>
&#13;
答案 0 :(得分:1)
在Angular2中使用ngFor而不是ng-repeat。
https://angular.io/docs/ts/latest/api/common/NgFor-directive.html