【发布时间】:2014-09-10 19:44:44
【问题描述】:
我有一个使用 $http.post 从 Angular 调用的 Django 视图
//LOADFILE ===================
this.loadfile = function (clickedItem) {
$http.post('/display/' , { "filename": clickedItem.fileName} )
.success(function(data) {
$scope.fileView.text = data;
$scope.fileView.title = clickedItem.title
}).error(function(data) {$scope.displayError=data});
};
如果 Django 抛出错误,数据将是一个完整的 Django 错误页面(完整的 html 页面)。
如何在 Angular 下显示该错误页面(完整的 html 页面)? (这里有一些关于模态的讨论:AngularJS, show popups - The most elegant way?,但没有关于完整的 html 页面......)
我认为我可以使用框架元素和 dom 来做到这一点:
$window.frames['myErrorFrame'].document.innerHTML = $scope.displayError;
但这看起来不是很Angularish...这几乎可以做到,但是我仍然有直接写入dom的问题,因为src是一个字符串:insert an iframe into page dynamically in AngularJS
有没有更好的方法在 Angular 中显示完整的 html 页面字符串?
【问题讨论】:
-
这似乎是相关的:stackoverflow.com/questions/9381926/… 但它不能处理完整的 html 页面(带有 js 和 css 等);这就是 Django 发送的内容。
-
也许将其保存在模板缓存中,然后调用它来填充您的 ng-view。一旦你在 templateCache 中有它,你可以把它放在任何 ng-include 中,你甚至可以打开一个 modal 并显示其中的内容。
-
有趣的想法...我试过了: angular.element("#errorIFrame").append($compile(data));但这没有用(到目前为止)。我将阅读 templateCache。看起来像一个选项。
标签: python html django angularjs