gpt4 book ai didi

javascript - 在 Angular JS 中使用 iFrame

转载 作者:行者123 更新时间:2023-12-03 11:54:18 24 4
gpt4 key购买 nike

我有两个不同的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com