我正在开发基于版本桌面/移动设备的功能略有不同的网站。
我尝试通过@View应用它,但看起来这个装饰器现在已被弃用。 请告诉我最佳实践,如何在Angular 2中实现此功能。
答案 0 :(得分:7)
@Component({
selector: 'my-component',
templateUrl: "./" + (window.screen.width > 900 ?
"my-component.desktop.html" :
"my-component.mobile.html"),
styleUrls: ['./my-component.css']
})
答案 1 :(得分:4)
ng2-responsive
包应该满足您的需求:https://www.npmjs.com/package/ng2-responsive
我还没有广泛使用它,但似乎做得不错。
@View
已合并到@Component
(很久以前)。 @Component
应该是您需要的唯一装饰器。
答案 2 :(得分:3)
目前最好替换@View
装饰者使用*ngIf
这样:
<div *ngIf="isMobile">
modile stuff
</div>
<div *ngIf="!isMobile">
desktop stuff
</div>