Skip to content

Instantly share code, notes, and snippets.

@chrillewoodz
Created July 26, 2017 18:45
Show Gist options
  • Save chrillewoodz/a62492521eb6692ea9a6aa07052b77e2 to your computer and use it in GitHub Desktop.
Save chrillewoodz/a62492521eb6692ea9a6aa07052b77e2 to your computer and use it in GitHub Desktop.
import {
ChangeDetectionStrategy,
Component,
forwardRef,
Input
} from '@angular/core';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
// Custom
import {Utils} from '@services/utils.service';
import {CustomValidators} from '@validators/custom-validators';
@Component({
moduleId: module.id,
selector: 'switch',
templateUrl: './switch.component.html',
styleUrls: ['./switch.component.scss'],
providers: [
{provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => SwitchComponent), multi: true}
],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class SwitchComponent implements ControlValueAccessor {
@Input() disabled: boolean;
private _model: boolean;
public id: string = Utils.getUniqueID();
constructor() {}
get model() {
return this._model;
}
set model(val) {
this._model = val;
this.propagateChange(val);
}
propagateChange: any = () => {};
validateFn: any = () => {};
writeValue(value) {
if (value) {
this.model = value;
}
}
registerOnChange(fn) {
this.propagateChange = fn;
}
registerOnTouched() {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment