Skip to content

Instantly share code, notes, and snippets.


Brian Troncone btroncone

View GitHub Profile
btroncone /
Last active Apr 19, 2022
Cleaning up subscriptions in Angular

Which do you prefer?

Adding to common sub, calling subscription.unsubscribe() in ngOnDestroy:

export class MyComponent {
  private _subscription: Subscription;
  ngOnInit() {
    this._subscription = myObservable
btroncone / service.spec.ts
Last active Sep 4, 2019
Angular service testing (constructor)
View service.spec.ts
import { inject, TestBed } from '@angular/core/testing';
import { of } from 'rxjs/observable/of';
import { LoggingService, LocalStorageService } from '../';
import { RouterEventService } from '../../routing';
export class MockLocalStorageService {
setItem() {}
getItem() { return []; }
export class MockRouterEventService {
btroncone /
Created Mar 30, 2016
angular 2 basic counter

angular 2 basic counter

Basic counter in Angular 2.

btroncone /
Created Mar 30, 2016
@ngrx/store counter

@ngrx/store counter

Basic counter w/ @ngrx/store.

btroncone /
Last active Jan 23, 2023
RxJS 5 Operators By Example
btroncone /
Last active Jan 28, 2023
A Comprehensive Introduction to @ngrx/store - Companion to Series

Comprehensive Introduction to @ngrx/store

By: @BTroncone

Also check out my lesson @ngrx/store in 10 minutes on!

Update: Non-middleware examples have been updated to ngrx/store v2. More coming soon!

Table of Contents

btroncone / bootstrap.ts
Last active May 10, 2021
Basic demonstration of how NgRx middleware can be used to keep local storage in sync with user-defined state slices.
View bootstrap.ts
//specify what state slices you would like to keep synced with local storage
export function main() {
return bootstrap(TodoApp, [
localStorageMiddleware('todos', 'visibilityFilter')
.catch(err => console.error(err));
btroncone / todo-item.ts
Last active Feb 20, 2019
Ng2 Observable Todo-Service
View todo-item.ts
import {Component, Input, Output, EventEmitter} from "angular2/core";
import {Todo} from "../services/Todo-Service";
selector: 'todo-item',
styles: [
text-decoration: line-through;
btroncone / authentication.ts
Last active Apr 10, 2022
Angular 2 application role access decorator, wrapping built in CanAccess functionality. Prevents view transitions when user roles are not appropriate.
View authentication.ts
import { Injectable } from 'angular2/core';
import { Storage } from './storage';
import { CurrentUser } from '../interfaces/common';
export class Authentication{
private _storageService : Storage;
private _userKey : string = "CURRENT_USER";
constructor(storageService : Storage){