Skip to content

Instantly share code, notes, and snippets.

View adrianfaciu's full-sized avatar
🎯
Focusing

Adrian Fâciu adrianfaciu

🎯
Focusing
View GitHub Profile
export class AppPreloadingStrategy implements PreloadingStrategy {
preload(route: Route, load: Function): Observable<any> {
const loadRoute = (delay) => delay
? timer(150).pipe(flatMap(_ => load()))
: load();
return route.data && route.data.preload
? loadRoute(route.data.delay)
: of(null);
}
}
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 }}
@NgModule({
providers: [
{
provide: externalUrlProvider,
useValue: (route: ActivatedRouteSnapshot) => {
const externalUrl = route.paramMap.get('externalUrl');
window.open(externalUrl, '_self');
},
},
],
const trace = x => (console.log(x), x)
const two = trace(2); //? 2
export class ToastData {
type: ToastType;
text?: string;
template?: TemplateRef<any>;
templateContext?: {};
}
selectStep(stepIndex: number) {
const step = this._steps.toArray()[stepIndex];
if (step) {
step.select();
}
}
public static forRoot(config = defaultToastConfig): ModuleWithProviders {
return {
ngModule: ToastModule,
providers: [
{
provide: TOAST_CONFIG_TOKEN,
useValue: { ...defaultToastConfig, ...config },
},
],
};
<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>
export const defaultToastConfig: ToastConfig = {
position: {
top: 20,
right: 20,
},
animation: {
fadeOut: 2500,
fadeIn: 300,
},
};