Skip to content

Instantly share code, notes, and snippets.

@Foovanadil
Foovanadil / minMaxValidator.ts
Last active February 27, 2017 22:12
Min Max validator directives for Angular 2 (since they don't exist currently in angular 2)
import { Directive, forwardRef, Attribute, Injectable, ElementRef, Input } from '@angular/core';
import { NG_VALIDATORS, Validator, AbstractControl, FormControl } from '@angular/forms';
import { CustomValidators } from './customValidators';
@Directive({
selector: '[min][formControlName],[min][formControl],[min][ngModel]',
providers: [{
provide: NG_VALIDATORS,
useExisting: forwardRef(() => MinValidator),
multi: true
import { Injectable } from '@angular/core';
import { AbstractControl } from '@angular/forms';
@Injectable()
export class CustomValidators {
min(control: AbstractControl, value: number): { [key: string]: boolean } {
return control.value >= value ? null : { 'min': true };
}
@Foovanadil
Foovanadil / clientsideFileDownload.js
Last active August 12, 2024 21:57
JS Clientside download file from blob
const clientsideDownloadFile = (blob,fileName) => {
// Test download attribute first
if ('download' in HTMLAnchorElement.prototype) {
// Create an object URL for the blob object
const url = URL.createObjectURL(blob);
// Create a new anchor element
const a = document.createElement('a');
a.href = url;
a.download = fileName;