Skip to content

Instantly share code, notes, and snippets.

View eliraneliassy's full-sized avatar
:octocat:
Angularing...

Eliran Eliassy eliraneliassy

:octocat:
Angularing...
View GitHub Profile
import { enableProdMode, NgModuleRef } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
import { createCustomElement } from '@angular/elements';
import { MyElementComponent } from 'my-element';
if (environment.production) {
enableProdMode();
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
@eliraneliassy
eliraneliassy / store.service.ts
Created March 21, 2020 12:48
store.service.ts
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class StoreService {
constructor() {
console.log('New StoreService instance created');
}
import { Subscription } from 'rxjs';
export function Unsubscriber() {
return (cmpType) => {
const originalFactory = cmpType.ngComponentDef.factory;
cmpType.ngComponentDef.factory = (...args) => {
const cmp = originalFactory(...args);
cmpType.ngComponentDef.onDestroy = () => {
if (cmp.ngOnDestroy) {
@Component({
selector: 'app-timer-example',
template: `
<div>
<app-timer *ngIf="alive"></app-timer>
</div>
<button (click)="destroy()" class="btn btn-danger">Destroy</button>
<button (click)="revive()" class="btn btn-primary">Revive</button>
`,
styleUrls: ['./timer-example.component.scss']
@Component({
selector: 'app-timer',
template: `
TimerComponent:
{{counter}}
`,
styleUrls: ['./timer.component.scss']
})
export class TimerComponent implements OnInit, OnDestroy {
import { Component, OnInit, ɵrenderComponent, ɵɵdirectiveInject, INJECTOR, Injector } from '@angular/core';
@Component({
selector: 'app-feature',
template: `
<button class="btn btn-primary" (click)="loadCounter()">Load Counter</button>
<my-host></my-host>
`,
styleUrls: ['./feature.component.scss']
{
path: 'dynamic-import',
loadChildren: () => import('./feature/feature.module').then((m) => m.FeatureModule)
}
@Component({
selector: 'app-child',
template: `
<div class="list-group">
<div class="list-group-item" *ngFor="let item of numbers">
{{item}}
</div>
</div>
`,
styleUrls: ['./child.component.scss'],
@Component({
selector: 'app-child',
template: `
<div class="list-group">
<div class="list-group-item" *ngFor="let item of numbers">
{{item}}
</div>
</div>
`,
styleUrls: ['./child.component.scss'],