javascript - angularJS UI选项卡打印选项卡中选定的内容

标签 javascript angularjs

我有嵌套的 angularJS 选项卡,我的问题是我希望能够打印选择内容列表,无论用户从父选项卡和子选项卡中选择什么。当用户单击打印列表时它会打印所有页面吗? http://plnkr.co/edit/8iYDDRaGHi2iNm0MWGfL?p=preview

$scope.printEmployeeList = function (divName) {
    var printContents = document.getElementById(divName).innerHTML;
    var popupWin = window.open('', '_blank', 'width=800,height=700');
    popupWin.document.open();
    popupWin.document.write('<html><head><link rel="stylesheet" type="text/css" href="style.css" /></head><body onload="window.print()">' + printContents + '</html>');
    popupWin.document.close();
}

最佳答案

您可以在按钮单击时编写一条指令,它将为您提供所选选项卡的内容。

标记

<button print-content="content">Employee List</button>

指令

app.directive('printContent', function($document) {
  return {
    restrict: 'A',
    compile: function(element, attrs) {
      element.on('click', function(event) {
        console.log($document.find('#'+ attrs.printContent).find('.tab-pane.active').html());
        //you code add your print code here
      });
    }
  }
});

Working Plunkr

关于javascript - angularJS UI选项卡打印选项卡中选定的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29567205/

相关文章:

javascript - 为什么我必须包含 JS 文件才能在每个 View 中使用 jquery?

javascript - 单击图标时向计时器添加第二秒

json - 跨域 $http 请求 AngularJS

angularjs - 将 ui-router $stateParams 传递给 $http 工厂服务

javascript - 如何连接从api接收到的字符串

javascript - 将 .slideUp() 和 .slideDown() 添加到搜索结果?

javascript - 单击 "scroll"箭头时的转换

javascript - ng-options 删除所选选项后,如何保持 ng-model 与选择元素同步

javascript - Angular js - 绑定(bind)到函数

angularjs - 如何在 Angular UI Bootstrap 中查看模态是否打开