ej-angular2/ej/radiobutton.component.ts

78 строки
2.3 KiB
TypeScript

import 'syncfusion-javascript/Scripts/ej/web/ej.radiobutton.min';
import { CommonModule } from '@angular/common';
import { EJComponents } from './core';
import { EventEmitter, Type, Component, ElementRef, ChangeDetectorRef, Input, Output, NgModule, ModuleWithProviders, Directive, forwardRef } from '@angular/core';
import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';
const noop = () => {
};
export const RadioButtonValueAccessor: any = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => RadioButtonComponent),
multi: true
};
@Component({
selector: '[ej-radiobutton]',
template: '',
host: { '(ejchange)': 'onChange($event.value)', '(change)': 'onChange($event.value)', '(focusOut)': 'onTouched()' },
providers: [RadioButtonValueAccessor]
})
export class RadioButtonComponent extends EJComponents<any, any> implements ControlValueAccessor
{
@Input('options') options: any;
@Input('checked') checked_input: any;
@Input('cssClass') cssClass_input: any;
@Input('enabled') enabled_input: any;
@Input('enablePersistence') enablePersistence_input: any;
@Input('enableRTL') enableRTL_input: any;
@Input('htmlAttributes') htmlAttributes_input: any;
@Input('id') id_input: any;
@Input('idPrefix') idPrefix_input: any;
@Input('name') name_input: any;
@Input('size') size_input: any;
@Input('text') text_input: any;
@Input('validationMessage') validationMessage_input: any;
@Input('validationRules') validationRules_input: any;
@Input('value') value_input: any;
@Output('beforeChange') beforeChange_output = new EventEmitter();
@Output('change') change_output = new EventEmitter();
@Output('ejchange') ejchange_output = new EventEmitter();
@Output('create') create_output = new EventEmitter();
@Output('destroy') destroy_output = new EventEmitter();
constructor(public el: ElementRef, public cdRef: ChangeDetectorRef) {
super('RadioButton', el, cdRef, []);
}
onChange: (_: any) => void = noop;
onTouched: () => void = noop;
writeValue(value: any): void {
if (this.widget) {
this.widget.option('model.value', value);
} else {
this.model.value = value;
}
}
registerOnChange(fn: (_: any) => void): void {
this.onChange = fn;
}
registerOnTouched(fn: () => void): void {
this.onTouched = fn;
}
}
export var EJ_RADIOBUTTON_COMPONENTS: Type<any>[] = [RadioButtonComponent
];