Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 different views based on Desktop or Mobile

I'm working on web site, that has slight different functionality based on version desktop/mobile.

I tried to apply it via @View, but it looks like this decorator is now deprecated. Please, advise me best practice, how to implement this feature in Angular 2.

like image 623
SergiySev Avatar asked Sep 11 '16 21:09

SergiySev


2 Answers

@Component({
  selector: 'my-component',
  templateUrl: "./" + (window.screen.width > 900 ? 
                     "my-component.desktop.html" : 
                     "my-component.mobile.html"),
  styleUrls: ['./my-component.css']
})
like image 83
Aneil Martins Avatar answered Oct 07 '22 10:10

Aneil Martins


At the moment the best to replace @View decorator is using an *ngIf like this:

<div *ngIf="isMobile">
    modile stuff
</div>
<div *ngIf="!isMobile">
    desktop stuff
</div>
like image 20
Tinwor Avatar answered Oct 07 '22 09:10

Tinwor