Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何打开浏览器窗口并传递HTML内容?_Javascript_Html_Angularjs - Fatal编程技术网

Javascript 如何打开浏览器窗口并传递HTML内容?

Javascript 如何打开浏览器窗口并传递HTML内容?,javascript,html,angularjs,Javascript,Html,Angularjs,通过点击按钮“推”,我需要打开新窗口,并将HTML内容传递给它以显示它 以下是显示HTML的视图: 以下是控制器定义: var test = angular.module('test', []); test.controller('testController', ['$compile', '$scope','$window', function($compile, $scope, $window) { $scope.openWindow = function() {

通过点击按钮“推”,我需要打开新窗口,并将HTML内容传递给它以显示它

以下是显示HTML的视图:

以下是控制器定义:

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');
    };}]);
以下是HTML内容:

<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>

内塔名称:
迈克尔


内塔年龄: 25
我想在打开的窗口中显示的HTML是:

<label>Entar Name:</label>
<label>Michael</label>
<br/>
<br/>
<label>Entar Age:</label>
<label>25</label>
Entar名称:
迈克尔


内塔年龄: 25
这是

如何实现它?

非常简单。。。 加在后面

.open()

下面的代码

.document.write(“Lorem Ipsum”)

这是一个非常简单的。。。 加在后面

.open()

下面的代码

.document.write(“Lorem Ipsum”)


这里有一个函数,您可以将内容包含在documet.write()函数中

<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>

函数myFunction(){
var myWindow=window.open(“,”,“宽度=600,高度=100”);
myWindow.document.write(“内塔姓名:Michael

内塔年龄:25岁”); }
您可以在documet.write()函数中包含您的内容

<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>

函数myFunction(){
var myWindow=window.open(“,”,“宽度=600,高度=100”);
myWindow.document.write(“内塔姓名:Michael

内塔年龄:25岁”); }
请参考以下链接。请参考以下链接。但如何从控制器中的模板中获取html代码呢?例如,嘿@Michael,创建一个变量并在其中放入一些html代码。请看我的示例,但如何从控制器中的模板获取html代码?例如,嘿@Michael,创建一个变量并在其中放入一些html代码。看我的例子