以前,我曾经$sce.trustAsHtml(aString)在...模板中注入一个字符串(例如),
.state('urls', {
url: '/urls/{id}',
template: '
controller: 'UrlCtrl',
resolve: {
url: ['$stateParams', 'urls', function ($stateParams, urls) {
return urls.get($stateParams.id);
}]
}
})
app.controller('UrlCtrl', ['$sce', '$scope', 'url', function($sce, $scope, url) {
$scope.content = $sce.trustAsHtml(url.content);
}]);
现在,生成图形的html包含对其他文件的引用,例如.所以,我需要的文件的文件夹(.html,.css,.js)绘制的图表.我可以将整个文件夹放在我的服务器中,但问题是如何将这些文件注入模板.
我试过templateUrl: 'http://localhost:3000/tmp/ZPBSytN5GpOwQN51AAAD/index.html',localhost:3000/#/urls/58b8c55b5d18ed6163324fb4在浏览器中加载确实加载了html页面.但是,script.js未加载,Failed to load resource: the server responded with a status of 404 (Not Found)控制台日志中会显示错误.
有谁知道如何修改这个?
否则,有没有其他的方法来这样说src=http://localhost:3000/tmp/ZPBSytN5GpOwQN51AAAD/index.html(像iframe)?然后,在index.html将知道它指的script.js是在同一个文件夹中.
编辑1:在@Icycool的评论之后,我改为templateUrl: '/htmls/test.html',并且test.html包含
编辑2:我创建了两个用于测试目的的文件:index.html和script.js.这是一个吸烟者,既不是template也templateUrl,正如所解释的......