Print the content from the selected tab in AngularJS UI tab

In my AngularJS application, I have implemented nested tabs and encountered an issue. I am trying to enable users to print the selected content list from both parent and child tabs. Is there a way to achieve this so that when a user clicks on "print list," the entire page is printed? Check out this link for reference.

$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();
}

Answer №1

If you click a button, you can create a directive that will display the content of the selected tab.

Example

<button show-tab-content="content">Employee Information</button>

Custom Directive

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

See Demo on Plunkr

Answer №2

If you need to print specific content, simply move that content into a child tab and wrap it in a div tag. This will allow you to print only the desired content. Take a look at this example on Plunker: http://embed.plnkr.co/tB1lUvIsL3TS8LGYmnCk/preview

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Reducing the size of textures in three.js

Is it possible to shrink the faces of a model rendered in the browser using Threejs, without affecting the mesh structure? I am looking for suggestions on how to accomplish this unique task. ...

How can I prevent text highlighting on a website?

Is there a way to lock the copy button on my site without restricting the save as button, which is activated by right click? I want users to be able to save the website as an HTML file, but prevent them from copying text. Can this be achieved using Javas ...

An issue occurred while trying to serialize cookies retrieved in getServerSideProps

I am currently working on a project using Reactjs with Next.js. I recently implemented a login module using cookies, but encountered an issue when trying to serialize the .cookies object returned from getServerSideProps. The error message states that undef ...

Incorporate fresh data into an array organized by groups using Javascript

I am looking to update my grouped array with new records. For example: var cars = [{ make: 'audi', model: 'r8', year: '2012' }, { make: 'audi', model: 'rs5', year: '2013' }, { make: 'ford& ...

Using Regular Expressions in JavaScript to verify if an element from an array is contained within a string

Looking for a simple JavaScript code for a Vue application that will split the string into an array and check if any value is present in a different string. Here's what I have: let AffiliationString = " This person goes to Stony Brook" ...

A guide on breaking down a URL string containing parameters into an array with the help of JavaScript

I need help splitting a long string into an array with specific index structure like this: fname=bill&mname=&lname=jones&addr1=This%20House&... I am looking to have the array set up as shown below: myarray[0][0] = fname myarray[0][1] = b ...

When the `readonly` attribute is set to 'true' in the `md-chips` component, a placeholder must still be

In my project, I am using the md-chips template like this: <md-chips dropdown ng-model="chipArray" readonly="true" md-on-remove="blah($chip)" ng-click="blahBlah()" placeholder="Add an item"> <md-chip-template><span>{{$chip.name ...

What is causing my React-Testing Library queries to not work at all?

In my current project, I am using Jest along with Testing-Library to create UI unit tests. One issue that I encountered was that the components were not rendering on the DOM. After some investigation, I found that the main culprit was a component called & ...

How to efficiently insert multiple documents into MongoDB using JavaScript

I'm currently working on inserting data into a MongoDB collection. I have a loop set up where I am receiving sample data in each iteration as shown below: 13:24:24:007,Peter,male,3720,yes 13:24:24:007,John,female,1520,yes 13:24:24:023,John,female,972 ...

After the data has finished loading, AngularJS will apply the directive to each select tag every time

I have created a directive that needs to be applied on each 'select' tag, but because it involves parsing the select data, it should be done after the data has been loaded. Unfortunately, the code I wrote only works on the last select item: ...

Unsubscribing from a service method in Javascript using RxJS

After clicking a button, a function is triggered to execute. The function includes an method called "executeAction" that retrieves the current view and then passes it as a parameter to another view for future reference. async executeAction(action: ...

Clicking React useState causes it to update before the intended click is registered

My goal is to create 50 buttons that, when clicked, will update the value of useState to the current button number (array index+1). However, I've encountered an issue where I have to click a button twice to get the correct value. The first click alway ...

Issue encountered: ENOENT - There is no file or directory located at the specified path for ... .steampath

I am encountering an issue while attempting to launch the development server on a React project that has been dormant for quite some time. After executing npm install and npm start, I encountered the following error message. Despite my efforts to manua ...

Error: Koa.js framework is unable to find the "users" relation in the Sequelize database

I am currently facing an issue while attempting to establish a relationship between two tables, 'user' and 'accessToken'. The error message I am encountering is hindering the process. Below are the models in question:- User model:- ...

What are the steps for creating a dropdown menu that allows for easy selection of the correct item

I am dealing with a dropdown menu as shown below. <select name="slt"> <option value="1">One</option> <option value="2">Two</option> <option value="3">Three</option> <option value="3">Three +</option&g ...

Obtaining specific data from the forEach iteration, post-click event with JavaScript

Trying to access the value from a Tree-structured Array of Objects stored in Local Storage, https://i.sstatic.net/YJ1PI.png Created a function that retrieves values from local storage using forEach and displays them on the screen. https://i.sstatic.net/ ...

Testing the controllers of directives in Angular without exposing them globally through unit tests

In an insightful repository by Vojta Jina showcasing directive testing, he places the directive controller outside of the module wrapper. You can view it here: https://github.com/vojtajina/ng-directive-testing/blob/master/js/tabs.js Do you think this pra ...

In strict mode, duplicate data properties are not allowed in object literals when using grunt-connect-proxy

I recently started following a tutorial on AngularJS titled "Hands on Angularjs" by Tutsplus. In the tutorial, the instructor uses the grunt-connect-proxy package to redirect ajax requests to a Rails server running on localhost:3000. However, I believe the ...

The process of extracting values from an HTML tag using Angular interpolation

I am working on an Angular application that has the following code structure: <p>{{item.content}}</p> The content displayed includes text mixed with an <a> tag containing various attributes like this: <p>You can find the content ...

In which part of my code should I implement the string to numerical function for my OrderBy function?

I successfully implemented a sortable header for my table with no errors, everything is functioning as expected. However, there is a small issue that I anticipated beforehand. The data in my JSON is string-based with numerical values that include symbols l ...