Display a table using Angular's md-card and md-color

Hey there! I'm currently working on printing a table that is filled with data in an md-card. The background color is set using the md-color theme picker, which you can check out here. However, I'm encountering an issue where the printed table only shows the data without the design of the md-card and md-color. I found a sample to work with on CodePen. Any help on this matter would be greatly appreciated. Thank you!

Here's the code snippet:

<table align="center" id="print-section">
            <tr ng-repeat="student in class">
                <td>
                    <md-card class="student-badge" md-colors="{background: '{{primary}}-500'}">
                        <md-card-title class="student-badge-title">
                            <md-card-title-text>
                                <span class="student-name">{{student.name}}</span>
                            </md-card-title-text>
                        </md-card-title>
                        <md-card-content>
                            <span class="badge" id="student-info">{{student.id}}</span>
                        </md-card-content>
                    </md-card>
                </td>
            </tr>
        </table>

Javascript snippet:

$scope.print = function() {
        var contents = document.getElementById("print-section").outerHTML;
        console.log("print " + contents);
        var frame1 = document.createElement('iframe');
            frame1.name = "frame3";
            frame1.style.position = "absolute";
            frame1.style.top = "-1000000px";
            document.body.appendChild(frame1);
            var frameDoc = frame1.contentWindow ? frame1.contentWindow : frame1.contentDocument.document ? frame1.contentDocument.document : frame1.contentDocument;
            frameDoc.document.open();
            frameDoc.document.write('<html><head><style>All styles and angular dependencies are added here</script></style>');
            frameDoc.document.write('</head><body>');
            frameDoc.document.write(contents);
            frameDoc.document.write('</body></html>');
            frameDoc.document.close();
            setTimeout(function () {
              window.frames["frame3"].focus();
              window.frames["frame3"].print();
              document.body.removeChild(frame1);
          }, 500);
          return false;
      };

Answer №1

After troubleshooting, I discovered the solution to my problem. When building a new page using Angular, remember to include all dependencies in Framedoc.document.write and double check for any syntax errors. In my situation, the issue was a missing HTML tag. Hopefully, this information will assist others facing similar challenges!

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

The functionality of Ng-Show is acting up

$scope.stay = function() { alert("Inside Keep me In") $scope.timed = false; $scope.isLogStatus = true; } $scope.displayAlert = function() { $scope.timed = true; alert("inside display") } function idleTimer() { var t; $window.o ...

Google Analytics does not include e-commerce tracking capabilities

Testing out the e-commerce-tracking feature, I modified Google's standard-script to ensure its functionality: <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i ...

Ways to create auto-suggest recommendations that exceed the boundaries of the dialogue container

Is there a way to position autosuggest suggestions above the dialog instead of within it, in order to prevent scrolling of dialog content? Check out this sandbox example for reference: https://codesandbox.io/embed/adoring-bogdan-pkou8https://i.sstatic.net ...

Dealing with numerous identical ajax requests in jQuery

With 5 text fields where various amounts are entered, I utilize AJAX calls for calculations based on these values. The issue arises when the same AJAX call is repeated each time a user types in order to determine the total amount. The problem lies in the ...

Creating an empty array of objects in Vue 3 requires using the Vue 3 syntax

In my project using Vue3 with Nuxt, I encountered an issue. My goal is to initialize an empty array of objects and then populate it. let results = ref([]); results.value = [ { "name": input.value, } ...

The function image.getState is not recognized (when trying to implement ol in an Angular project)

I attempted to integrate the code provided in an angular(4) application at the following link: However, I encountered an error every time I tried to launch the browser. To start with, here are my imports (both libraries were locally installed via npm): ...

Seamless side-to-side navigation

Currently, I am working on a website that has horizontal overflow instead of the common vertical scroll. While everything seems to be functioning properly, I need to enhance the user experience by adjusting the amount scrolled to move larger sections of th ...

Adding fresh data to a C3.js line graph

I am attempting to dynamically update a C3.js line chart using a function that retrieves a set of x and y values from a database. The function I want to use for inserting the data is: function insertGraph(yAxis, xAxis, Header) { setTimeout(function () ...

How can Angular hide a global component when a particular route is accessed?

Is it possible to hide a global component in Angular when a specific route is opened? For instance, consider the following code: app.component.html <app-header></app-header> <app-banner></app-banner> <!-- Global Component I w ...

Automatically identify the appropriate data type using a type hint mechanism

Can data be interpreted differently based on a 'type-field'? I am currently loading data from the same file with known type definitions. The current approach displays all fields, but I would like to automatically determine which type is applicab ...

Seeking clarification on how to load an angular directive

I am puzzled by the fact that in the given jsFiddle, 'here is a log' gets printed three times. http://jsfiddle.net/wg385a1h/5/ $scope.getLog = function () { console.log('here is a log'); } Could anyone shed some light on why thi ...

Creating a dynamic directive in AngularJS: Learn how to add or remove it from the DOM based on specific conditions

Suppose I have a customized modal directive that looks like this: return { restrict: 'E', templateUrl: 'modal.html', scope: { modalContent: "&", modalOpen: "&" } } And in the HTML: <ng-modal modal-content="co ...

Command for controlling volume in DiscordJS

Despite my efforts, I am struggling to write a command that successfully changes the volume of the music being played. Every time the player and resource variables in the volume() function are empty while the bot is playing the song. What can I do to resol ...

I noticed that when I call my add function from the index view button in AngularJS, the counter value changes but it is not reflecting on the UI. Why is this happening?

FirstController.js function FirstController($scope) { $scope.$apply(function () { $scope.add = function (amount) { $scope.counter += amount; } });} The View - **Addtion.html** <div ng-controller="FirstController"> ...

Navigating through the realm of Android development entails understanding how to manage a multi-object function in JavaScript when using

In order to load an HTML page using the webview component and handle its functions, I am faced with a challenge. The HTML page contains a multi-object named (webkit.messageHandlers.adClicked). How can I utilize the webView.addJavascriptInterface() functi ...

Ensure that the alert for an Ajax JSON record count remains active when the count is

Trying out Ajax JSON for the first time has been a bit tricky. Even though I hard coded "Record: 1" on the server side, it keeps alerting me with a total record of 0. I'm not sure where I went wrong. Could it be an issue with how I passed the array da ...

The specified selector is invalid or illegal in HTMLUnit

Attempting to mimic a login using htmlunit has presented me with an issue despite following examples. The console messages I have gathered are as follows: runtimeError: message=[An invalid or illegal selector was specified (selector: '*,:x' erro ...

Maximizing the efficiency of Java Script code

I am struggling with optimizing this JavaScript code that adds and removes classes based on the presence of a specific class in the next rows of a table. Can anyone provide some guidance on how to make this code more efficient? $(".showTR").click(functi ...

"Implement image uploading and retrieval functionality in your application by utilizing Parse and Back4App with the help of Node

It seems like I have a question that may have already been answered, but I can't find the right solution for my issue. I'm facing trouble with my code and can't figure out what's wrong. The problem arises when I try to upload specific ...

Should objects passed as props be modified in Vue.js components?

I've observed that in Vue, object fields passed as Props can be changed, and these changes reflect in the parent component. Is this considered a bad practice? Should it be avoided, or is it acceptable to use? What are the potential pitfalls of this a ...