Angular2 Web与Mobile TemplateURL [英] Angular2 Web vs Mobile TemplateURL
本文介绍了Angular2 Web与Mobile TemplateURL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在网站的网络版本和移动版本中重复使用组件.这些网站差异很大,因此响应式设计不可行.
I'd like to reuse components for a web version of my website as well as a mobile version. The websites are vastly different so responsive design is not feasible.
理想情况下,有一种方法可以根据屏幕分辨率提供多个templateUrl,但我认为不存在这种情况.
Ideally, there would be a way to provide multiple templateUrls based on the screen resolution, but I don't think something like this exists.
示例:
@Component({
selector: 'multiplatform-component',
templateUrl-sm: 'app/sm.html',
templateUrl-md: 'app/md.html',
})
解决此问题的最佳方法是什么?
What is the best way to approach this?
推荐答案
您可以创建全局函数来解析templateURL
s:
You could create global function to resolve templateURL
s:
function getTemplateURL(url:string){ /* check browser, etc. */ };
@Component({
selector: 'multiplatform-component',
templateUrl: getTemplateURL('app/sm.html')
})
这篇关于Angular2 Web与Mobile TemplateURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文