1

By click on button "push" I need to open new window and pass to it HTML content to display it.

Here is view that display HTML:

enter image description here

Here is controller definition:

var test = angular.module('test', []);

test.controller('testController', ['$compile', '$scope','$window', function($compile, $scope, $window) {
    $scope.openWindow = function() {
        $window.open('to-print', 'width=500,height=400');
    };}]);

Here is HTML content:

<div ng-app="test" id = "content" ng-controller="testController">
<label>Entar Name:</label>
<label>Michael</label>
<br/>
<br/>
<label>Entar Age:</label>
<label>25</label>
<hr/>
    <button ng-click="openWindow()">push!</button>
</div>

And the HTML I want to display inside opened window is:

<label>Entar Name:</label>
<label>Michael</label>
<br/>
<br/>
<label>Entar Age:</label>
<label>25</label>

Here is fiddle.

How can I implement it?

1

2 Answers 2

2

You can include your content in documet.write() function

<script>
    function myFunction() {
        var myWindow = window.open("", "","width=600,height=100");
        myWindow.document.write("<label>Entar Name:</label><label>Michael</label><br/><br/><label>Entar Age:</label><label>25</label>");
    }
</script>
Sign up to request clarification or add additional context in comments.

Comments

1

It's very simple... Add after

.open()

the following code

.document.write("Lorem Ipsum");

Here is a jsfiddle

2 Comments

But how can I get html code from template in my controller?
Hey @Michael, for example create a variable and put some html code inside. See my example jsfiddle.net/d8atdw0t/273

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.