[英]whats the best way to handle ng-include not found?
I have page which includes a file dynamically like so: 我有一个页面,其中包含一个动态地像这样的文件:
<div ng-include="filename + '.html'"><div>
This works if the file exists. 如果文件存在,此方法有效。 Otherwise it throws a big ugly console error.
否则,它将引发严重的控制台错误。
Is there an elegant way to handle this in angular? 是否有一种优雅的方式来解决这个问题? eg something like:
例如:
<div ng-include="'somefile.html'" ng-ifnexist="'default-page.html'"></div>
Whats the best approach? 最好的方法是什么?
This is getting a bit messy, and ngIf is effectivly deprecated in favour of Directives, but what about 这变得有些混乱,并且有效地弃用了ngIf,以支持Directives,但那又如何呢?
<div ng-if="[list of possible names].indexOf(filename) > -1">
<div ng-include="filename + '.html'" ></div>
</div>
<div ng-if="[list of possible names].indexOf(filename) == -1">
<div ng-include="'default-page.html'" ></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.