File

src/app/modules/core/directives/desktop-only/desktop-only.directive.ts

Implements

OnInit

Metadata

Index

Properties
Methods

Constructor

constructor(templateRef: TemplateRef, viewContainer: ViewContainerRef)
Parameters :
Name Type Optional
templateRef TemplateRef<any> No
viewContainer ViewContainerRef No

Methods

ngOnInit
ngOnInit()
Returns : void

Properties

Private hasView
Default value : false
import { Directive, TemplateRef, ViewContainerRef, OnInit } from '@angular/core';
import { environment } from '@sunbird/environment';

@Directive({
  selector: '[appDesktopOnly]'
})
export class DesktopOnlyDirective implements OnInit {
  private hasView = false;
  constructor(
    private templateRef: TemplateRef<any>,
    private viewContainer: ViewContainerRef) { }

  ngOnInit() {
    const isDesktopApp = environment.isDesktopApp;
    if (isDesktopApp && !this.hasView) {
      this.viewContainer.createEmbeddedView(this.templateRef);
      this.hasView = true;
    } else if (!isDesktopApp && this.hasView) {
      this.viewContainer.clear();
      this.hasView = false;
    }
  }
}

results matching ""

    No results matching ""