Skip to content

Instantly share code, notes, and snippets.

export interface State {
mediaPlaying: boolean;
audioPlaying: boolean;
videoPlaying: boolean;
}
ngOnInit() {
this.store.dispatch({type: "GET_USERS"});
}
ngOnDestroy() {
this.store.dispatch({type: "CANCEL_GET_USERS"})
}
ngOnInit() {
this.users$ = this.userService.users$;
}
export interface State {
items: {[index: number]: Item};
favoriteItems: number[];
}
export function favoriteItemsReducer(state = initialState, action: Action) {
switch(action.type) {
case 'REMOVE_FAVORITE_ITEM':
case 'DELETE_ITEM_SUCCESS':
const itemId = action.payload;
return state.filter(id => id !== itemId);
default:
return state;
}
}
import {Directive, Input} from '@angular/core';
@Directive({
selector: '[patchFormGroupValues]',
})
export class PatchFormGroupValuesDirective {
@Input() formGroup: any;
@Input()
set patchFormGroupValues(val: any) {
if (!val) return;
import {Directive, Input} from '@angular/core';
import {NgControl} from '@angular/forms';
@Directive({
selector: '[setValue]',
})
export class SetValueDirective {
@Input()
set setValue(val: any) {
this.ngControl.control.setValue(val);
import {Directive, Input} from '@angular/core';
@Directive({
selector: '[disableFormGroup]',
})
export class DisableFormGroupDirective {
@Input() form: any;
@Input() formGroupName: string;
@Input()
set disableFormGroup(disabled: boolean) {
import {Directive, Input} from '@angular/core';
import {NgControl} from '@angular/forms';
@Directive({
selector: '[disableControl]',
})
export class DisableControlDirective {
@Input()
set disableControl(disabled: boolean) {
const method = disabled ? 'disable' : 'enable';