Skip to content

Instantly share code, notes, and snippets.

Credit to https://gist.github.com/iansinnott/3d0ba1e9edc3e6967bc51da7020926b0
export class UploadComponent {
@ViewChild('file') file: ElementRef;
imagePreview$: Observable<ArrayBuffer | string>;
onFile(event) {
event.preventDefault();
event.stopPropagation();
this.file.nativeElement.click();
export interface State {}
const state: State = {};
export class Store {
private subject = new BehaviorSubject<State>(state);
private store = this.subject.asObservable().distinctUntilChanged();
get value() {
import { Injectable } from '@angular/core';
import { select, Store } from '@ngrx/store';
import { Credentials } from '../../models';
import { State } from '../reducers';
import {
selectError,
selectLoading,
selectIsAuthenticated,
selectToken
import { Inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { CONFIG, Config } from '../config.module';
@Injectable({
providedIn: 'root'
})
export class ConfigLoaderService {
configUrl: string;
import { TestBed, async, inject } from '@angular/core/testing';
import { StoreModule, Store, ActionReducerMap } from '@ngrx/store';
export const accountReducer: ActionReducerMap<{}> = {
status: {}
};
import { AccountGuard } from './account.guard';
describe('AccountGuard', () => {
let store: Store<{}>;
@Injectable({
providedIn: 'root'
})
export class AuthGuard implements CanActivate, CanLoad {
constructor(private store: Store<AuthState>) {}
canActivate(): Observable<boolean> {
return this.store.pipe(
select(selectIsAuthenticated),
map(isValidToken => {
import { Injectable } from '@angular/core';
import { select, Store } from '@ngrx/store';
import { Credentials } from '../../models';
import { AuthState } from '../reducers';
import {
selectError,
selectLoading,
selectLoggedIn,
selectToken
import { Component, OnInit } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import {
animate,
animateChild,
group,
query,
style,
transition,
trigger } from '@angular/animations';
export enum AuthActionTypes {
Login = '[Auth] Page Login',
LoginFailure = '[Auth] Api Login Failure',
LoginSuccess = '[Auth] Api Login Success',
Logout = '[Auth] Page Logout',
LogoutFailure = '[Auth] Api Logout Failure',
LogoutSuccess = '[Auth] Api Logout Success'
}
// These are important and needed before anything else
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import { join } from 'path';
import * as express from 'express';
import * as cookieParser from 'cookie-parser';
import * as helmet from 'helmet';
import { enableProdMode } from '@angular/core';
// Faster server renders w/ Prod mode (dev mode never needed)