@angular/common#isPlatformServer TypeScript Examples
The following examples show how to use
@angular/common#isPlatformServer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: product-control.sandbox.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 6 votes |
constructor(
private router: Router,
protected appState$: Store<store.AppState>,
public snackBar: MatSnackBar,
@Inject(PLATFORM_ID) private platformId: Object
) {
this.productTotal = 0;
this.completeOrder();
if (isPlatformBrowser(this.platformId)) {
const cartParams: any = {};
cartParams.products = sessionStorage.getItem('selectedProducts')
? JSON.parse(sessionStorage.getItem('selectedProducts'))
: [];
cartParams.productTotal = sessionStorage.getItem('selectedProductsCount')
? +JSON.parse(sessionStorage.getItem('selectedProductsCount'))
: 0;
cartParams.totalPrice = sessionStorage.getItem('productTotal')
? +JSON.parse(sessionStorage.getItem('productTotal'))
: 0;
this.HandleCart(cartParams);
}
if (isPlatformServer(this.platformId)) {
}
}
Example #2
Source File: slick.component.ts From flingo with MIT License | 6 votes |
/**
* On component view checked
*/
ngAfterViewChecked() {
if (isPlatformServer(this.platformId)) {
return;
}
if (this._addedSlides.length > 0 || this._removedSlides.length > 0) {
const nextSlidesLength = this.slides.length - this._removedSlides.length + this._addedSlides.length;
if (!this.initialized) {
if (nextSlidesLength > 0) {
this.initSlick();
}
// if nextSlidesLength is zere, do nothing
} else if (nextSlidesLength === 0) {
// unslick case
this.unslick();
} else {
this._addedSlides.forEach((slickItem) => {
this.slides.push(slickItem);
this.slick.addSlide(slickItem.el.nativeElement);
});
this._addedSlides = [];
this._removedSlides.forEach((slickItem) => {
const idx = this.slides.indexOf(slickItem);
this.slides = this.slides.filter((s) => s !== slickItem);
this.slick.removeSlide(idx);
});
this._removedSlides = [];
}
}
}
Example #3
Source File: ngx-hide-on-scroll.directive.ts From Elastos.Essentials.App with MIT License | 5 votes |
init() {
if (isPlatformServer(this.platformId)) {
return;
}
this.reset();
let elementToListenScrollEvent;
let scrollingElement: HTMLElement;
if (!this.scrollingElementSelector) {
elementToListenScrollEvent = window;
scrollingElement = this.getDefaultScrollingElement();
} else {
scrollingElement = document.querySelector(this.scrollingElementSelector) as HTMLElement;
if (!scrollingElement) {
console.warn(`NgxHideOnScroll: @Input() scrollingElementSelector\nElement with selector: "${this.scrollingElementSelector}" not found.`);
return;
}
elementToListenScrollEvent = scrollingElement;
}
/* elementToListenScrollEvent.addEventListener("scroll", e => {
console.log("MANUAL ON SCROLL", e)
}) */
/* elementToListenScrollEvent.addEventListener("ionScroll", e => {
console.log("MANUAL ON ION-SCROLL", e)
})
*/
const scroll$ = fromEvent<ScrollCustomEvent>(elementToListenScrollEvent, 'ionScroll').pipe(
takeUntil(this.unsubscribeNotifier),
throttleTime(50), // only emit every 50 ms
map(event => event.detail.scrollTop), // get vertical scroll position
pairwise(), // look at this and the last emitted element
// compare this and the last element to figure out scrolling direction
map(([y1, y2]): ScrollDirection => (y2 < y1 ? ScrollDirection.Up : ScrollDirection.Down)),
distinctUntilChanged(), // only emit when scrolling direction changed
share(), // share a single subscription to the underlying sequence in case of multiple subscribers
);
const scrollUp$ = scroll$.pipe(
filter(direction => direction === ScrollDirection.Up)
);
const scrollDown$ = scroll$.pipe(
filter(direction => direction === ScrollDirection.Down)
);
let scrollUpAction: () => void;
let scrollDownAction: () => void;
if (this.hideOnScroll === 'Up') {
scrollUpAction = () => this.hideElement(scrollingElement);
scrollDownAction = () => this.showElement(scrollingElement);
} else {
scrollUpAction = () => this.showElement(scrollingElement);
scrollDownAction = () => this.hideElement(scrollingElement);
}
scrollUp$.subscribe(() => {
scrollUpAction()
});
scrollDown$.subscribe(() => {
scrollDownAction()
});
}
Example #4
Source File: ngx-tippy-group.component.ts From ngx-tippy-wrapper with MIT License | 5 votes |
ngAfterViewInit() {
if (isPlatformServer(this.platform)) return;
this.setTooltips();
}
Example #5
Source File: ngx-tippy-singleton.component.ts From ngx-tippy-wrapper with MIT License | 5 votes |
ngAfterViewInit() {
if (isPlatformServer(this.platform)) return;
this.setSingleton();
}
Example #6
Source File: ngx-tippy.directive.ts From ngx-tippy-wrapper with MIT License | 5 votes |
ngOnInit() {
if (isPlatformServer(this.platform)) return;
this.ngxViewService.viewContainerRef = this.viewContainerRef;
this.initTippy();
}
Example #7
Source File: request.interceptor.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 5 votes |
intercept(req: HttpRequest<any>, next: HttpHandler) {
// this.spinner.show();
if (isPlatformBrowser(this.platformId)) {
this.userTokenDetail = localStorage.getItem('userToken');
}
if (isPlatformServer(this.platformId)) {
}
if (this.userTokenDetail) {
req = req.clone({
setHeaders: {
Authorization: 'Bearer ' + this.userTokenDetail
}
});
}
return next.handle(req).pipe(
map((user: any) => {
if (user instanceof HttpResponse) {
const response = user.body;
if (
response.message &&
response.message !== '' &&
req.method !== 'GET' &&
response.message !== 'Redirect to this url.'
) {
this.showSuccess(user.body.message);
}
}
return user;
}),
catchError(response => {
this.spinner.hide();
if (response.status === 200 || response.status === 201) {
return response;
}
switch (response.status) {
case 400:
this.handleBadRequest(response);
break;
case 401:
this.handleUnAuthorized();
break;
case 403:
this.handleUnAuthorized();
break;
case 500:
this.handleServerError();
break;
default:
break;
}
return throwError(response);
})
);
}
Example #8
Source File: gantt-dom.service.ts From ngx-gantt with MIT License | 5 votes |
getResize(): Observable<Event> {
return isPlatformServer(this.platformId) ? EMPTY : fromEvent(window, 'resize').pipe(auditTime(150));
}