Skip to content

Instantly share code, notes, and snippets.

View MarkPieszak's full-sized avatar
🐈
@ Trilon

Mark Pieszak MarkPieszak

🐈
@ Trilon
View GitHub Profile
@ThomasBurleson
ThomasBurleson / untilDestroyed.ts
Last active April 18, 2023 07:47
Using untilViewDestroyed to link component ngOnDestroy to observable unsubscribe.
/**
* When manually subscribing to an observable in a view component, developers are traditionally required
* to unsubscribe during ngOnDestroy. This utility method auto-configures and manages that relationship
* by watching the DOM with a MutationObserver and internally using the takeUntil RxJS operator.
*
* Angular 7 has stricter enforcements and throws errors with monkey-patching of view component life-cycle methods.
* Here is an updated version that uses MutationObserver to accomplish the same goal.
*
* @code
*
@J2D2Development
J2D2Development / es6-umd.js
Created August 10, 2017 16:38
Replace es6 with umd bundle
'use strict';
const { readFile, writeFile } = require('fs');
const { join } = require('path');
readFile(join(__dirname, '../dist-server/main.bundle.js'), 'utf-8', (err, data) => {
if(err) { return console.log('Error reading file:', err); }
const ssrPageScrollBundle = 'ng2-page-scroll/bundles/ng2-page-scroll.umd.js'
const newCode = data.replace('ng2-page-scroll', ssrPageScrollBundle)
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import * as io from 'socket.io-client';
@Injectable()
export class SocketService {
socket: any;
private host: string = `${window.location.protocol}//${window.location.hostname}:${window.location.port}`;
@PatrickJS
PatrickJS / ssr_material_fix.ts
Last active September 27, 2018 05:57
Angular 4 universal fixes for Material 2
global['document'] = {
createElement() {
return {
setAttribute: function(type) { this.type = type; },
type: '',
classList: { add: () => undefined }
};
},
documentElement: {
getBoundingClientRect: () => ({
import { Injectable, Optional, Inject } from '@angular/core';
import { APP_BASE_HREF } from '@angular/common';
import { NodePlatformLocation, REQUEST_URL, ORIGIN_URL } from 'angular2-platform-node';
import { Response, Request } from 'express';
/**
* Issue HTTP 302 redirects on internal redirects
*/
@Injectable()
@KostyaEsmukov
KostyaEsmukov / _ express-redirect-platform-location.md
Last active October 20, 2023 20:55
HTTP redirects with Angular SSR

HTTP redirects with Angular Server Side Rendering

This service assumes that you followed the SSR receipt at ng-cli (i.e. you use the '@nguniversal/express-engine' package).

import { Injectable, Inject } from '@angular/core';
import { DomAdapter } from '@angular/platform-browser/src/dom/dom_adapter';
import { __platform_browser_private__, DOCUMENT} from '@angular/platform-browser';
@Injectable()
export class SeoService {
private _dom: DomAdapter = __platform_browser_private__.getDOM();
constructor(@Inject(DOCUMENT) private _document: any) { }
setTitle(title: string) {
@orgbx
orgbx / angular2-meta.ts
Last active April 15, 2018 14:18
Working Angular 2 meta service with solution for "export function getDOM()" error
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Injectable, Inject } from '@angular/core';
import { DomAdapter } from '@angular/platform-browser/src/dom/dom_adapter';
import { __platform_browser_private__, DOCUMENT} from '@angular/platform-browser';

@ngrx/store v3

Problems:

  • Users want to compose reducer tree across modules
  • Idea of a single reducer function makes it difficult for the library to dynamically augment the shape of the state tree
  • Turning control over to the library to build the root reducer limits the use of meta-reducers
  • Feature modules may inadvertently collide with the state of the root module
  • Library authors may want to leverage @ngrx/store in their projects and provide an easy way
@Directive({
selector: '[universalAd],[universal-ad]'
})
class UniversalAd {
constructor(
@Attribute('id') public id: string,
public adRegistry: MyAdRegistry,
public elementRef: ElementRef,
public cdRef: ChangeDetectorRef) {