Angular 2 different views based on Desktop or Mobile

前端 未结 3 654
说谎
说谎 2021-02-03 12:12

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

相关标签:
3条回答
  • 2021-02-03 12:50

    The ng2-responsive package should cover your needs: https://www.npmjs.com/package/ng2-responsive

    I haven't used it extensively yet, but it seems to be doing a decent job.

    @View was merged into @Component (ages ago). @Component should be the only decorator you need.

    0 讨论(0)
  • 2021-02-03 12:52

    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>
    
    0 讨论(0)
  • 2021-02-03 12:59
    @Component({
      selector: 'my-component',
      templateUrl: "./" + (window.screen.width > 900 ? 
                         "my-component.desktop.html" : 
                         "my-component.mobile.html"),
      styleUrls: ['./my-component.css']
    })
    
    0 讨论(0)
提交回复
热议问题