unicorn-components
Version:
<a target="_blank" href="https://getunicorn.io"><img src="https://bitbucket-assetroot.s3.amazonaws.com/c/photos/2017/Jul/07/2615006260-5-nitsnetsstudios-ondemand-UNI_avatar.png" align="left"></a>
45 lines (39 loc) • 1.4 kB
text/typescript
import { AfterContentInit, Component, ContentChildren, HostBinding, Input, QueryList } from '@angular/core';
import { UniInputBaseComponent } from '../../base/input-base/input-base.component';
import { UniRadioComponent } from '../radio/radio.component';
export class UniRadioGroupComponent extends UniInputBaseComponent implements AfterContentInit {
private _model;
componentClass = true;
set model(value) {
this._model = value;
this.initRadiosModels();
}
get model() { return this._model; }
radios: QueryList<UniRadioComponent>;
ngAfterContentInit() {
this.initRadios();
this.radios.changes.subscribe(() => this.initRadios());
}
private initRadios() {
this.initRadiosListeners();
this.initRadiosModels();
}
private initRadiosModels() {
if (!this.radios) { return; }
this.radios.forEach(item => item.model = this.model);
}
private initRadiosListeners() {
this.radios.forEach(
item => item.modelChange.subscribe(
value => {
this.model = value;
this.onNgModelChange(value);
}
)
);
}
}