创建从控制器新的HTML页 [英] Creating a new html page from controller

查看:93
本文介绍了创建从控制器新的HTML页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入表格页,即当用户提交,它更新该网页的数据的一些表。如果用户喜欢他们所看到的,他们应该能够打印清理(无头资产净值,页脚导航等),这些表的版本格式不变。

I have an input form page, that when the user submits, it updates that page with some tables of data. If the user likes what they see, they should be able to print a cleaned up (no header nav, footer nav, etc) version of those tables with formatting intact.

我创建使用引导和angularjs表。我想要做的是,当点击USET打印,我的角度控制器抓起从生成页面所需的内容(在一个名为模板的div),并把它插入到一个新的HTML页面,我可以再开在打印的新窗口。

I'm creating the tables using bootstrap and angularjs. What I'm trying to do is that when the uset clicks 'print', my angular controller grabs the desired content from the generated page (in a div called 'template') and inserts it into a new html page that I can then open in a new window for printing.

我创造了我希望可以让我用一个指令 $编译来transclude我的数据:

I created a directive that I was hoping would allow me to use $compile to transclude my data:

app.directive('printTemplate', function () {
    return {
        templateUrl: 'app/partials/printtemplate.html',
        replace: true,
        transclude: true,
        restrict: 'A'
    };
});

在我的控制器:

$scope.printTemplate = function () {
    var page = angular.element(template).contents();
    var newpage = $compile("<html><body><div print-template>" + page + "</div></body></html>")($scope);
    var win = window.open();
    win.document.write(newpage);
    //win.print();
};

但是,这似乎并没有做什么,我的期望。而且感觉像我这样做是错误的。当时的想法是因为我的数据表需要启动脚本和CSS引用我需要包括在我的 printtemplate.html 文件。

有没有更简单/更好的方式来做到这一点,还是我缺少什么?

Is there an easier/better way to do this, or what am I missing?

推荐答案

而不是试图创造一个全新的页面,为什么不直接使用打印媒体特定的CSS。

Instead of trying to create a whole new page, why not simply use specific css for print media.

一如往常的W3是开始 HTTP的最佳场所://www.w3。组织/ TR / CSS2 / media.html

As always the w3 is the best place to start http://www.w3.org/TR/CSS2/media.html

这篇关于创建从控制器新的HTML页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆