Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Adrian Fâciu adrianfaciu

🏠
Working from home
View GitHub Profile
View keyvalue_test.ts
import { TestBed, async, ComponentFixture } from "@angular/core/testing";
import { Component } from "@angular/core";
import { By } from "@angular/platform-browser";
@Component({
selector: "dh-app-div",
template: `
<span *ngFor="let item of foo | keyvalue">
{{ item }}
View comma_operator.js
const trace = x => (console.log(x), x)
const two = trace(2); //? 2
View select-step.ts
selectStep(stepIndex: number) {
const step = this._steps.toArray()[stepIndex];
if (step) {
step.select();
}
}
View toast.component_v3.html
<ng-container *ngIf="data.text; else templateRef">
{{ data.message }}
</ng-container>
<ng-template #templateRef>
<ng-container *ngTemplateOutlet="data.template; context: data.templateContext">
</ng-container>
</ng-template>
View toast_data.ts
export class ToastData {
type: ToastType;
text?: string;
template?: TemplateRef<any>;
templateContext?: {};
}
View toast_for_root.ts
public static forRoot(config = defaultToastConfig): ModuleWithProviders {
return {
ngModule: ToastModule,
providers: [
{
provide: TOAST_CONFIG_TOKEN,
useValue: { ...defaultToastConfig, ...config },
},
],
};
View toast_config_default.ts
export const defaultToastConfig: ToastConfig = {
position: {
top: 20,
right: 20,
},
animation: {
fadeOut: 2500,
fadeIn: 300,
},
};
View toast_config.ts
export interface ToastConfig {
position?: {
top: number;
right: number;
};
animation?: {
fadeOut: number;
fadeIn: number;
};
}
View fade_out_handler.ts
onFadeFinished(event: AnimationEvent) {
const { toState } = event;
const isFadeOut = (toState as ToastAnimationState) === 'closing';
const itFinished = this.animationState === 'closing';
if (isFadeOut && itFinished) {
this.close();
}
}
View toast.component_v3.html
<div class="toast"
[@fadeAnimation]="{value: animationState, params:
{ fadeIn: 1000, fadeOut: 1000 }}">
<mat-icon>{{ iconType }}</mat-icon>
<div>{{ data.text }}</div>
<mat-icon (click)="close()">close</mat-icon>
</div>
You can’t perform that action at this time.