Skip to content

Instantly share code, notes, and snippets.

View armanozak's full-sized avatar

Levent Arman Özak armanozak

View GitHub Profile
@armanozak
armanozak / abstract-ng-model.component.ts
Last active June 4, 2019 08:05
An Abstract Component with Accessible Value and More #blog
import { ControlValueAccessor } from '@angular/forms';
import { ChangeDetectorRef, Component, Injector, Input, Type } from '@angular/core';
import { uuid } from '../utils/generators';
@Component({ template: '' })
export class AbstractNgModelComponent<T = any> implements ControlValueAccessor {
@Input()
cid: string = uuid();
@Input()
@armanozak
armanozak / abstract-ng-model.component.shell.ts
Last active May 9, 2019 08:24
The Shell of an Abstract Component with Accessible Value #blog
import { ControlValueAccessor } from '@angular/forms';
import { Component } from '@angular/core';
@Component({ template: '' })
export class AbstractNgModelComponent<T = any> implements ControlValueAccessor {
/*
This is where boilerplate code for ControlValueAccessor
and any other reusable property or method will be placed
*/
@armanozak
armanozak / sample.component.ts
Last active May 9, 2019 08:24
A Sample Component with a Value Accessible via FormControlName, FormControlDirective or NgModel Directives #blog
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { Component, forwardRef, Input } from '@angular/core';
@Component({
providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => SampleComponent),
multi: true,
}],