Skip to content

Instantly share code, notes, and snippets.

constructor(private state: AppStateService) {
this.state.onUserChanges.subscribe(
user => { console.log('New Email: ' + user.email); }
);
this.state.user = new User({ email: 'test@test.net' });
// console: New Email: test@test.net;
}
export interface IAppStateService {
user: IUser;
onUserChanges: Subject<IUser>;
}
@Injectable({
providedIn: 'root'
})
export class AppStateService implements IAppStateService {
export interface IAppStateService {
user: IUser;
onUserChanges: Subject<IUser>;
}
@Injectable({
providedIn: 'root'
})
export class AppStateService implements IAppStateService {
import { Subject } from 'rxjs';
export interface IUser {
username: string;
email: string;
}
export class User implements IUser {
private _email: string = '';
private _username: string = '';
import { User, IUser } from '../classes/user'
import { Subject } from 'rxjs';
export interface IGlobalComponentState {
user: IUser;
}
export class GlobalComponentState implements IGlobalComponentState {
private _user: User = new User();
onUserChanges = new Subject<User>();
@reed-lawrence
reed-lawrence / user.ts
Last active December 3, 2019 19:46
Cross-component change detection observables
export interface IUser {
username: string;
email: string;
}
export class User implements IUser {
email: string = '';
username: string = '';
constructor(init?: Partial<IUser>) {
@reed-lawrence
reed-lawrence / dom.service.ts
Last active July 7, 2022 18:37 — forked from caroso1222/dom.service.ts
Service to dynamically append Angular components to the body
import {
Injectable,
Injector,
ComponentFactoryResolver,
EmbeddedViewRef,
ApplicationRef,
ComponentRef
} from '@angular/core';
@Injectable()