如何在组件 Angular 2 中分离移动和桌面的模板和样式?

How to separate template and style for mobile and desktop in component Angular 2?

移动端和桌面端的模板有很大的不同,但在组件中有一个逻辑。我需要单独的文件中的移动和桌面模板和设计。我想要根据屏幕包括模板和设计。

您可以使用*ngIf

template: `
<div *ngIf="isMobile">
  mobile content
</div>
<div *ngIf="!isMobile">
  desktop content
</div>

Angular2 团队曾尝试使用 @View() 装饰器直接支持这一点,但在几个版本前将其删除,因为这似乎不是一个好的策略。目前没有内置支持你想要的东西。