Skip to content

Instantly share code, notes, and snippets.

View wh0th3h3llam1's full-sized avatar

wh0am1 wh0th3h3llam1

View GitHub Profile
@wh0th3h3llam1
wh0th3h3llam1 / common.interface.ts
Created November 14, 2022 19:34
Form & Common Service to get Dirty Controls in Angular along with a custom field mapping (date -> string)
export interface IDirtyControl {
field: string,
type: string,
convertTo: string,
}
@wh0th3h3llam1
wh0th3h3llam1 / non_fields_errors-form.component.html
Last active May 7, 2022 21:31
Render `non_field_errors` in Angular Ant Design
...
<nz-alert nzType="error" [nzMessage]="nonFieldErrors" *ngIf="non_field_errors.length > 0" nzShowIcon>
<ng-template #nonFieldErrors>
<nz-list>
<nz-list-item *ngFor="let error of non_field_errors">{{ error }}</nz-list-item>
</nz-list>
</ng-template>
</nz-alert>
...
@wh0th3h3llam1
wh0th3h3llam1 / error.service.ts
Last active May 14, 2022 06:54
Error Service to render form errrors
import { HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { Router } from '@angular/router';
import { NzMessageService } from 'ng-zorro-antd/message';
@Injectable({
providedIn: 'root'
})
export class ErrorService {
<form nz-form [formGroup]="validateForm" (ngSubmit)="submitForm(validateForm.value)">
<nz-form-item>
<nz-form-label [nzSpan]="9" nzRequired>Name</nz-form-label>
<nz-form-control [nzSpan]="6" [nzErrorTip]="nameError">
<input nz-input formControlName="name" placeholder="Name" />
</nz-form-control>
<ng-template #nameError let-control>
<ng-container *ngIf="control.hasError('serverError')">
{{ control.errors.serverError }}
@wh0th3h3llam1
wh0th3h3llam1 / keybindings.json
Created April 25, 2022 17:19
VS Code Dotfiles
// Place your key bindings in this file to override the defaultsauto[]
[
{
"key": "ctrl+l ctrl+t",
"command": "editor.action.transformToTitlecase"
},
{
"key": "ctrl+l ctrl+l",
"command": "editor.action.transformToLowercase"
},
import { Component, OnInit } from '@angular/core';
import { AbstractControl, FormBuilder, FormGroup, ValidatorFn, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { take } from 'rxjs/operators';
import { HttpErrorResponse } from '@angular/common/http';
import { ErrorService } from 'src/app/services/error.service';
<div>
<nz-breadcrumb [nzSeparator]="separatorTemplate">
<nz-breadcrumb-item *ngFor="let breadcrumb of breadcrumbs">
<ng-container *ngIf="breadcrumb.isClickable; else notClickable">
<a [routerLink]="breadcrumb.url">
<ng-container *ngIf="breadcrumb.icon; else noIcon">
<i nz-icon [nzType]="breadcrumb.icon"></i>
</ng-container>
<ng-template #noIcon>
<img [src]="breadcrumb.image" height="20px" width="20px" alt="" *ngIf="breadcrumb.image;">
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
import { IBreadcrumb } from './breadcrumb.interfaces';
import { filter, distinctUntilChanged } from 'rxjs/operators';
@Component({
selector: 'app-breadcrumb',
templateUrl: './breadcrumb.component.html',
styleUrls: ['./breadcrumb.component.css']
@wh0th3h3llam1
wh0th3h3llam1 / breadcrumb.interface.ts
Created March 25, 2022 07:13
Breadcrumb Interface
export interface IBreadcrumb {
icon: string,
image: string,
url: string,
label: string,
isClickable: boolean
}
@wh0th3h3llam1
wh0th3h3llam1 / your-component.component.html
Created March 25, 2022 07:07
Basic Static Breadcrumb Code
<div>
<nz-breadcrumb>
<nz-breadcrumb-item>
<a routerLink="/">
<i nz-icon nzType="home"></i>
</a>
</nz-breadcrumb-item>
<nz-breadcrumb-item>
<a routerLink="/university">
<img src="assets/images/university_icon.svg" height="20px" width="20px" alt="">