【发布时间】:2014-01-17 03:38:35
【问题描述】:
当我使用ng-include作为标题时,地址(文件路径)不存在时如何捕捉错误?
我在ng-view(with ng-route) 中完成了ng-include router,
有点像这样:
内容控件:
var content = $route.current.params.content,
tmplArr = content.split("_"),
tmpl = {},
personId=$route.current.params.personId||$scope.persons[0].id;
$scope.personId=personId;
tmpl.url = "content/";
for (var i = 0, len = tmplArr.length; i < len; i++) {
tmpl.url += tmplArr[i] + "/";
}
tmpl.url = tmpl.url.substring(0, tmpl.url.length - 1) + ".html";
$scope.template = tmpl;
内容视图:
<div ng-include="template.url" class="ng-animate"></div>
当我使用 addr 时,例如:/home/#/content/profile_asdfa, 角度只是在循环中获取资源。 因此,当哈希中没有模板文件时,我需要捕获 ng-include 错误。 有谁能够帮我 ?谢谢!
【问题讨论】:
-
与您的问题无关,但最好不要在元素中包含
ng-animate类。当 Angular 执行其进入/离开动画时,它会自动添加(+ 删除),因此它可能会导致稍微不可预测的行为。
标签: javascript angularjs angularjs-ng-include