javascript - 在 Angular JS 中使用 iFrame

标签 javascript html grails iframe

我有两个不同的 html 页面。我想使用 iframe 将第二个显示到第一个中。这两个 html 页面都位于 asset/templates/mainapp/下的 grail-app 文件夹中。 我正在使用 ngroute 作为页面。

第一个 html 页面是

    <!-- @author Karan Shah -->
<body>
    <div>
        <h1>Document Display Contents</h1>

        <!-- Back -->
        <a href="#/documents">Back to the List of Documents</a>

        <!-- Get the name of the selected document from previous view to be displayed on current view  -->
        <br>    
        <div ng-controller='displaycontrol'>
            You are viewing : <b>{{doc}}</b>
        </div>

        <!-- Http get request to get the text of the document to controller -->
        <br>    
        <div ng-controller='textcontrol'>
            {{textofdocument}}
        </div>

        <div>
            <iframe ng-src="/maindocument.html">Fail</iframe>
        </div>
    </div>
</body>

第二个 HTML 页面是 (maindocument.html)

<!DOCTYPE html>
<html >
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Hello how are you ??
</body>
</html>

Controller 文件

/**
 * @author Karan Shah
 * 
 */

var documentDisplayModule = angular.module('ald.documentdisplay',[]);

// Selected document name from previous view gets displayed on the document display view using $routeParams
documentDisplayModule.controller('displaycontrol',['$scope','$routeParams', function($scope,$routeParams){
    $scope.doc=$routeParams.doc;
}]);

// $http.get to get the text based on the selected document
documentDisplayModule.controller('textcontrol',['$scope','$http','$routeParams',function($scope,$http,$routeParams){
    $http.get("/document/getContents?docName="+$routeParams.doc).success(function(datatext){
    $scope.textofdocument=datatext;
    })
}])

documentDisplayModule.controller('framecontrol',['$scope',function($scope){
    $scope.docurl="assets/templates/mainapp/maindocument.html";
}])

我认为我没有正确获取 src。有人可以告诉我来源应该是什么吗?我无法显示任何内容。这是我在调试时遇到的错误:

GET http://localhost:8080/maindocument.html 404 (Not Found) 

最佳答案

源应该是您的文件夹中 maindocument.html 所在的位置

即。

Assets /模板/mainapp/maindocument.html

使用-

<iframe src="assets/templates/mainapp/maindocument.html"></iframe>

关于javascript - 在 Angular JS 中使用 iFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25665908/

相关文章:

javascript - React JS scrollIntoView() 不会一直向下滚动

JavaScript 仅在 Safari 开发控制台打开时才起作用

jquery - 从自定义文件输入中显示和删除文件名

Grails: getClass().getResource ("whatever") 不起作用

testing - 如何在特定方法中防止@Rollback?

spring - Datasource.groovy 在应用程序上下文加载之前执行?

javascript - Math.round 未按预期返回整数

javascript - 使用 Javascript AJAX(不是 jQuery)提交嵌入式 Mailchimp 表单

html - <g:if>和<g:set>在grails中的误解

javascript - 带有选择选项的 jquery 事件问题