How to use the @angular/common.isPlatformBrowser function in @angular/common

To help you get started, we’ve selected a few @angular/common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MurhafSousli / ngx-gallery / lib / gallerize / src / gallerize.directive.ts View on Github external
// Add click event to the image
              this._renderer.setStyle(img, 'cursor', 'pointer');
              this._renderer.setProperty(img, 'onclick', () => this._lightbox.open(i, this.gallerize));
              return img;
            }),
            tap((img: HTMLImageElement) => images.push(new ImageItem(img.src, img.src))),
            finalize(() => galleryRef.load(images))
          );
        } else {
          return empty();
        }
      })
    ).subscribe();

    // Observe content changes
    if (isPlatformBrowser(this.platform)) {
      this.observer = new MutationObserver(() => this.gallerizer$.next());
      this.observer.observe(this._el.nativeElement, { childList: true, subtree: true });
    }
  }
github angular / flex-layout-builds / esm2015 / core.js View on Github external
lookupStyle(element, styleName, inlineOnly = false) {
        /** @type {?} */
        let value = '';
        if (element) {
            /** @type {?} */
            let immediateValue = value = this.lookupInlineStyle(element, styleName);
            if (!immediateValue) {
                if (isPlatformBrowser(this._platformId)) {
                    if (!inlineOnly) {
                        value = getComputedStyle(element).getPropertyValue(styleName);
                    }
                }
                else {
                    if (this._serverModuleLoaded) {
                        value = this._serverStylesheet.getStyleForElement(element, styleName);
                    }
                }
            }
        }
        // Note: 'inline' is the default of all elements, unless UA stylesheet overrides;
        //       in which case getComputedStyle() should determine a valid value.
        return value ? value.trim() : '';
    }
    /**
github KoderLabs / ngx-device-detector / src / device-detector.service.ts View on Github external
public isTablet(userAgent = this.userAgent) {
        if (
          isPlatformBrowser(this.platformId) &&
          (
            !!this.reTree.test(this.userAgent, Constants.TABLETS_RE['iPad']) ||
            (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)
          )
        ) {
          return true;
        }
        const match = Object.keys(Constants.TABLETS_RE).find((mobile) => {
          return !!this.reTree.test(userAgent, Constants.TABLETS_RE[mobile]);
        });
        return !!match;
    };
github shyamseshadri / angular-up-and-running / chapter12 / server-side-rendering / src / app / app.module.ts View on Github external
constructor(
    @Inject(PLATFORM_ID) private platformId: Object,
    @Inject(APP_ID) private appId: string) {
    const platform = isPlatformBrowser(platformId) ?
      'in the browser' : 'on the server';
    console.log(`Running ${platform} with appId=${appId}`);
  }
}
github plone / plone.restapi-angular / src / authentication.service.ts View on Github external
getUserInfo() {
    if (isPlatformBrowser(this.platformId)) {
      let token = localStorage.getItem('auth');
      if (token) {
        let tokenParts = token.split('.');
        return JSON.parse(atob(tokenParts[1]));
      } else {
        return null;
      }
    }
  }
github sheikalthaf / ngu-carousel / src / app / carousel / ngu-carousel / ngu-carousel.component.ts View on Github external
private storeCarouselData(): void {
    if (isPlatformBrowser(this.platformId)) {
      this.data.deviceWidth = window.innerWidth;
    } else {
      this.data.deviceWidth = 1200;
    }
    this.data.carouselWidth = this.carouselMain.offsetWidth;

    if (this.data.type === 'responsive') {
      this.data.deviceType =
        this.data.deviceWidth >= 1200
          ? 'lg'
          : this.data.deviceWidth >= 992
            ? 'md'
            : this.data.deviceWidth >= 768
              ? 'sm'
              : 'xs';
github vmware / clarity / src / website / src / app / utils / hash-listener.directive.ts View on Github external
scrollToAnchor(hash: string, smooth = true) {
    if (hash && isPlatformBrowser(this.platformId)) {
      const element = document.querySelector('#' + hash);
      if (element) {
        element.scrollIntoView({
          behavior: smooth ? 'smooth' : 'auto',
          block: 'start',
        });
      }
    }
  }
github DSpace / dspace-angular / src / app / shared / utils / scroll-and-stick.directive.ts View on Github external
constructor(private _element: ElementRef, @Inject(NativeWindowService) private _window: NativeWindowRef, @Inject(PLATFORM_ID) private platformId) {
    if (isPlatformBrowser(platformId)) {
      this.subscribeForScrollEvent();
    }
  }
github EreckGordon / angular-universal-pwa-starter / src / client / app / shared / auth / social-module / social-auth.service.ts View on Github external
constructor(public authService: AuthService, @Inject(PLATFORM_ID) private platformId: Object) {
        this.providers = this.config.providers;
        if (isPlatformBrowser(this.platformId)) {
            this.providers.forEach((provider: LoginProvider, key: string) => provider.initialize());
        }
    }
github biig-io / ngx-smart-modal / src / ngx-smart-modal / src / services / ngx-smart-modal.service.ts View on Github external
private get isBrowser(): boolean {
    return isPlatformBrowser(this._platformId);
  }