import {
View,
Directive,
ElementRef,
Optional,
Parent,
NgControl
} from 'angular2/angular2';
import {Ion} from '../ion';
import {IonInputItem} from '../form/form';
import {IonicConfig} from '../../config/config';
import {IonicComponent, IonicView} from '../../config/annotations';
import {Icon} from '../icon/icon';
@IonicComponent({
selector: 'ion-checkbox',
host: {
'class': 'item',
'[attr.aria-checked]': 'checked'
},
defaultProperties: {
'iconOff': 'ion-ios-circle-outline',
'iconOn': 'ion-ios-checkmark'
}
})
@IonicView({
template:
'
' +
'' +
'' +
'
' +
'' +
'' +
'
'
})
export class Checkbox extends IonInputItem {
_checkbox: CheckboxInput;
constructor(
elementRef: ElementRef,
config: IonicConfig
) {
super(elementRef, config);
}
onAllChangesDone() {
// Enforce that this directive actually contains a checkbox
if (this._checkbox == null) {
throw 'No found inside of ';
}
}
registerInput(checkboxDir) {
if (this._checkbox != null) {
throw 'Only one is allowed per '
}
this._checkbox = checkboxDir.elementRef.nativeElement;
this._checkboxDir = checkboxDir;
}
onClick(e) {
let val = !this._checkbox.checked;
this._checkbox.checked = val;
this.checked = val;
//TODO figure out a way to trigger change on the actual input to trigger
// form updates
// this._checkbox.dispatchEvent(e);
//this._checkboxDir.control.valueAccessor.writeValue(val);
}
}
// export class CheckboxInput {
// constructor(
// elementRef: ElementRef,
// @Optional() @Parent() container: Checkbox,
// @Optional() control: NgControl
// ) {
// this.elementRef = elementRef;
// this.control = control ? control : null;
// container && container.registerCheckbox(this);
// }
// }