Skip to content

Instantly share code, notes, and snippets.

View armanozak's full-sized avatar

Levent Arman Özak armanozak

View GitHub Profile
@armanozak
armanozak / app.component.ts
Last active May 9, 2019 08:30
Angular Context - Two-way Data-binding (#4) #blog
@Component({
selector: 'my-app',
template: `
<form [formGroup]="form">
<context-provider provide="rate">
<two-way></two-way>
</context-provider>
</form>
{{ rate }}
@armanozak
armanozak / two-way.component.ts
Last active May 9, 2019 08:30
Angular Context - Two-way Data-binding (#3) #blog
@Component({
selector: 'two-way',
template: `
<ng-template
contextDisposer="rate onRating"
let-rate="rate"
let-onRating="onRating"
>
<rating
[ngModel]="rate"
@armanozak
armanozak / app.component.ts
Last active May 9, 2019 08:30
Angular Context - Two-way Data-binding (#2) #blog
@Component({
selector: 'my-app',
template: `
<context-provider provide="rate onRating">
<two-way></two-way>
</context-provider>
{{ rate }}
`,
})
@armanozak
armanozak / app.component.ts
Last active May 9, 2019 08:30
Angular Context - Two-way Data-binding (#1) #blog
@Component({
selector: 'my-app',
template: `
<context-provider provide="rate pre onRating">
<two-way></two-way>
</context-provider>
{{ rate }}
`,
})
@armanozak
armanozak / app.component.ts
Last active May 9, 2019 08:30
Angular Context - One-way Data-binding (#4) #blog
@Component({
selector: 'my-app',
template: `
<context-provider
provide="progress progressStriped progressType"
[contextMap]="{progressType: 'type'}"
>
<one-way></one-way>
</context-provider>
`,
@armanozak
armanozak / one-way.component.ts
Last active May 9, 2019 08:30
Angular Context - One-way Data-binding (#3) #blog
@Component({
selector: 'one-way',
template: `
<ng-template contextDisposer let-context>
<progressbar
[type]="context.type"
[value]="context.progress"
[striped]="context.progressStriped"
>{{ progress ? progress + '%' : '' }}</progressbar>
</ng-template>
@armanozak
armanozak / one-way.component.ts
Last active May 9, 2019 08:30
Angular Context - One-way Data-binding (#2) #blog
@Component({
selector: 'one-way',
template: `
<context-consumer consume="progress"></context-consumer>
<progressbar
contextConsumer
[contextMap]="{progress: 'value', progressStriped: 'striped'}"
>{{ progress ? progress + '%' : '' }}</progressbar>
`,
@armanozak
armanozak / app.component.ts
Last active May 9, 2019 08:30
Angular Context - One-way Data-binding (#1) #blog
@Component({
selector: 'my-app',
template: `
<context-provider
provide="progress progressStriped progressType"
[contextMap]="{progressType: 'type'}"
>
<one-way></one-way>
</context-provider>
`,
@armanozak
armanozak / input-text.component.ts
Last active May 9, 2019 08:25
Two Input Components Extending Abstract Input Component #blog
import { ChangeDetectionStrategy, Component, forwardRef, Input } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { AbstractInputComponent } from '../abstracts/input.component';
@Component({
selector: 'app-input-text',
template: `
<input [id]="cid"
[type]="type"
@armanozak
armanozak / abstract-input.component.ts
Last active May 9, 2019 08:25
An Abstract Input Component Extending Abstract NgModel Component #blog
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { AbstractNgModelComponent } from './ng-model.component';
@Component({ template: '' })
export class AbstractInputComponent extends AbstractNgModelComponent<string> {
@Input()
readonly: boolean = false;
@Input()
required: boolean = false;