Skip to content

Instantly share code, notes, and snippets.

@qdouble
qdouble / text-input.html
Last active August 25, 2016 15:17
text-input
<md-input
align="start"
[dividerColor]="dynamicControl.valid || (!dynamicControl.valid && dynamicControl.errors?.required) ? 'primary' : 'warn'"
floatingPlaceholder="true"
[placeholder]="(dynamicControl.errors?.required && !hideRequired) ? label + ' (required)' : label "
[formControl]="dynamicControl"
[hintLabel]="help">
</md-input>
<button *ngIf="submit" type="submit" [disabled]="!form.valid">{{submit}}</button>
@qdouble
qdouble / min-max.ts
Created August 26, 2016 11:07
Min-max validator
import { AbstractControl } from '@angular/forms';
import { ValidatorFn } from '@angular/forms';
export function minMax(min: number, max: number): ValidatorFn {
return (control: AbstractControl): { [key: string]: any } => {
return control.value < min || control.value > max ?
{ 'invalidNumber': true } :
<any>null;
};
}
@qdouble
qdouble / combine-sort.ts
Last active September 1, 2016 11:24
Sorting observable with combine latest and sort function
const sortOther = function (a, b, sortBy, reverse) {
let nameA = a[sortBy];
let nameB = b[sortBy];
if (reverse) {
nameA = b[sortBy];
nameB = a[sortBy];
}
if (nameA < nameB) {
return -1;
}
@qdouble
qdouble / webpack.config.ts
Last active February 12, 2018 20:19
Webpack 2 config for Angular2 with AOT and Production settings
/* tslint:disable: variable-name max-line-length */
import 'ts-helpers';
const {
HotModuleReplacementPlugin,
DefinePlugin,
ProgressPlugin,
NoErrorsPlugin,
optimize: {
CommonsChunkPlugin
@qdouble
qdouble / window.service.ts
Created September 8, 2016 12:10
Window service
import { OpaqueToken } from '@angular/core'
var win = typeof window !== 'undefined' && window || <any>{};
export { win as window };
function CONST_EXPR(expr) {
return expr;
}
function _window(): any {