I am making an app with NW and AngularJS to make a desktop app, what I want is to get the files from a server(html, css, js).
我正在使用NW和AngularJS创建一个应用程序来制作桌面应用程序,我想要的是从服务器(html,css,js)获取文件。
then I want to do something like the following code:
然后我想做类似下面的代码:
aux.config(function ($routeProvider) {
$routeProvider
.when('/testInformation/', {
templateUrl: 'https://serverName/test.html',
controller: 'shipmentInformationController'
}).otherwise({
redirectTo: '/'
});
});
The problem is that when I run the app it is not getting the html of the template, then I am not sure if this idea is valid on AngularJs or if I need change the logic of that to get the content of the html.
问题是,当我运行应用程序时,它没有得到模板的html,那么我不确定这个想法是否对AngularJs有效,或者我是否需要更改其逻辑以获取html的内容。
I am getting the error
我收到了错误
Error: $sce:insecurl Processing of a Resource from Untrusted Source Blocked
错误:$ sce:insecurl处理来自不受信任来源的资源被阻止
Thanks for any help.
谢谢你的帮助。
2 个解决方案
#1
2
You can't directly load content from a remote server due to Cross-Origin Resource Sharing rules.
由于跨源资源共享规则,您无法直接从远程服务器加载内容。
One relatively straightforward workaround is to proxy the content using something like Nginx to make it look like it came from your own server.
一个相对简单的解决方法是使用像Nginx这样的内容来代理内容,使其看起来像是来自您自己的服务器。
If you have control over the remote server, you could simply add an Access-Control-Allow-Origin
header.
如果您可以控制远程服务器,则只需添加一个Access-Control-Allow-Origin标头即可。
#2
0
I was doing some search on internet and I found a solution that works for me.
我在互联网上做了一些搜索,我发现了一个适合我的解决方案。
The idea is add a domain because by default angularJs only support the same domain, then we can add a white list with the "$sceDelegateProvider" like the folowing code
这个想法是添加一个域,因为默认情况下angularJs只支持相同的域,然后我们可以添加一个带有“$ sceDelegateProvider”的白名单,如下面的代码
.config(function ($sceDelegateProvider) {
$sceDelegateProvider.resourceUrlWhitelist([
// Allow same origin resource loads.
'self',
// Allow loading from our assets domain. Notice the difference between * and **.
'https://serverName.com/**'
]);
});
after that when we will set the templateURL, we can use the remote server.
之后,当我们设置templateURL时,我们可以使用远程服务器。
.when('/test1/', {
templateUrl: 'https://serverName.com/html/test1.html',
controller: 'test1'
#1
2
You can't directly load content from a remote server due to Cross-Origin Resource Sharing rules.
由于跨源资源共享规则,您无法直接从远程服务器加载内容。
One relatively straightforward workaround is to proxy the content using something like Nginx to make it look like it came from your own server.
一个相对简单的解决方法是使用像Nginx这样的内容来代理内容,使其看起来像是来自您自己的服务器。
If you have control over the remote server, you could simply add an Access-Control-Allow-Origin
header.
如果您可以控制远程服务器,则只需添加一个Access-Control-Allow-Origin标头即可。
#2
0
I was doing some search on internet and I found a solution that works for me.
我在互联网上做了一些搜索,我发现了一个适合我的解决方案。
The idea is add a domain because by default angularJs only support the same domain, then we can add a white list with the "$sceDelegateProvider" like the folowing code
这个想法是添加一个域,因为默认情况下angularJs只支持相同的域,然后我们可以添加一个带有“$ sceDelegateProvider”的白名单,如下面的代码
.config(function ($sceDelegateProvider) {
$sceDelegateProvider.resourceUrlWhitelist([
// Allow same origin resource loads.
'self',
// Allow loading from our assets domain. Notice the difference between * and **.
'https://serverName.com/**'
]);
});
after that when we will set the templateURL, we can use the remote server.
之后,当我们设置templateURL时,我们可以使用远程服务器。
.when('/test1/', {
templateUrl: 'https://serverName.com/html/test1.html',
controller: 'test1'