Javascript AngularJS包含位于文件夹中的文件
当我这样做的时候 /sites/all/themes/theme/js/controller.js /sites/all/themes/theme/js/index.htmlJavascript AngularJS包含位于文件夹中的文件,javascript,angularjs,Javascript,Angularjs,当我这样做的时候 /sites/all/themes/theme/js/controller.js /sites/all/themes/theme/js/index.html /sites/all/themes/theme/js/partials/tpl.html 好家伙! 我基本上把所有与angular相关的东西都放到了js文件夹中 它返回localhost/partials/tpl.html,而我需要localhost/sites/all/themes/js/partials/tpl.
/sites/all/themes/theme/js/partials/tpl.html
好家伙!
我基本上把所有与angular相关的东西都放到了js文件夹中
它返回localhost/partials/tpl.html
,而我需要localhost/sites/all/themes/js/partials/tpl.html
。如何在不使用绝对路径的情况下解决此问题?在index.html
中的
元素顶部添加一个
<html>
<head>
<base href="/sites/all/themes/theme/js/">
...
...
相对链接
确保检查所有相关链接、图像、脚本等。您必须
在主html文件()的头部指定url基,或者必须使用绝对url(从/)
因为相对URL将解析为绝对URL
使用文档的初始绝对url,通常是
与应用程序的根不同
从文档根目录启用历史API运行Angular应用程序
强烈鼓励,因为它会处理所有相关链接问题
在index.html
中的
元素顶部添加一个
<html>
<head>
<base href="/sites/all/themes/theme/js/">
...
...
相对链接
确保检查所有相关链接、图像、脚本等。您必须
在主html文件()的头部指定url基,或者必须使用绝对url(从/)
因为相对URL将解析为绝对URL
使用文档的初始绝对url,通常是
与应用程序的根不同
从文档根目录启用历史API运行Angular应用程序
强烈鼓励,因为它会处理所有相关链接问题
我使用$httpProvider.interceptors解决了这个问题。以下内容将“myAppDirectory”前置到所有请求
$httpProvider.interceptors.push(function($q) {
return {
'request': function(config) {
config.url = 'myAppDirectory/'+config.url;
return config;
},
};
});
常规ng包括,例如:
<div ng-include="'user/info.html'">
我使用$httpProvider.interceptors解决了这个问题。以下内容将“myAppDirectory”前置到所有请求
$httpProvider.interceptors.push(function($q) {
return {
'request': function(config) {
config.url = 'myAppDirectory/'+config.url;
return config;
},
};
});
常规ng包括,例如:
<div ng-include="'user/info.html'">
您可以创建一个JSFIDLE/plnkr吗?我有类似的实现在工作。如何在JSFIDLE或plnkr中包含来自其他文件夹的文件您可以创建JSFIDLE/plnkr吗?我有类似的实现工作。我如何在JSFIDLE或plnkrCould工作中包含来自其他文件夹的文件,但它会中断我的所有路由,我使用drupal作为backend@JonathandeM. 然后尝试在控制器中包含
$location
,并使用$scope.template=$location.path()+'/partials/tpl.html'
可以工作,但它会中断我的所有路由,我使用drupal作为backend@JonathandeM. 然后尝试在控制器中包含$location
,并使用$scope.template=$location.path()+'/partials/tpl.html'
$httpProvider.interceptors.push(function() {
return {
'request': function(config) {
// ignore api calls and ui-bootstrap templates.
if (config.url.indexOf('api')==-1 && config.url.indexOf('template')==-1) {
config.url = 'myAppDirectory/'+config.url;
}
return config;
},
};
});