简体   繁体   English

在Angular2中使用PhoneGap,加载模板时出现问题

[英]Using PhoneGap with Angular2, problems loading templates

It seems like systemjs can't seem to find the template files (my .html views) because it uses absolute paths to load the files. 似乎systemjs似乎找不到模板文件(我的.html视图),因为它使用绝对路径加载文件。 It expects my main app component app.html to be located at file:// but the fact is, PhoneGap places the root of the application pretty deep down the line of file://data/data/app-name/root/... The reason systemjs loads from / might be because i added a <base href="/"> to my index.html . 它希望我的主要应用程序组件app.html位于file://但事实是,PhoneGap将应用程序的根目录放置在file://data/data/app-name/root/...下一行file://data/data/app-name/root/... systemjs从/加载的原因可能是因为我在index.html添加了<base href="/"> This is done to get the routing to work though. 这样做是为了使路由正常工作。

What is the best practise here? 最佳做法是什么? All my components uses templateUrl and i'm seriously considering inlineing the html instead - which would be really annoying... 我所有的组件都使用templateUrl,而我正在认真考虑内联html,这确实很烦人...

I'm using traceur as transpiler. 我正在使用Traceur作为编译器。

If anyone is interested, i solved that problem in a two step fix: 如果有人感兴趣,我分两步解决了该问题:

First, in my index.html, where i import my app, before i do that, i initialize a global variable that i use later as a baseUrl: 首先,在我导入应用程序的index.html中,在此之前,我初始化一个全局变量,以后将其用作baseUrl:

if (window.cordova !== undefined) {
    baseLoadpath = 'data/data/dk.app_name/files/download/app_dir/';
} else {
    baseLoadpath = '/'
}

Whenever i load a template, i prepend this baseLoadPath like this: 每当我加载模板时,我都会像下面这样添加baseLoadPath:

@View({
    templateUrl : baseLoadpath + 'app.html' 
})

That takes care of the file paths. 那会照顾文件路径。 I still can't get it up and running in PhoneGap due to other erros... 由于其他错误,我仍然无法在PhoneGap中启动它并运行...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM