I used this solution Angular2 - Radio Button Binding for radio button binding. It worked fine under RC1.
But when I upgrade to Angular2 RC2. there is a compile error
app/shared/services/radio.value.accessor.ts(22,5): error TS2345:
Argument of type '{ selector: string;
host: { [x: string]: string; '(change)': string; '(blur)': string; };
binding...'
is not assignable to parameter of type '{ selector?: string;
inputs?: string[];
outputs?: string[];
properties?: string[];
events?: strin...'.
Object literal may only specify known properties, and 'bindings' does not exist in type
'{ selector?: string;
inputs?: string[];
outputs?: string[];
properties?: string[];
events?: strin...'.
The code is listed as below.
import {Directive, Renderer, ElementRef, forwardRef} from '@angular/core';
import {NG_VALUE_ACCESSOR, ControlValueAccessor} from '@angular/common';
export const RADIO_VALUE_ACCESSOR: any = /*@ts2dart_const*/ {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => RadioControlValueAccessor),
multi: true
};
/**
* The accessor for writing a value and listening to changes on a radio input element.
*
* ### Example
* ```
* <input type="radio" ngModel="radioModel">
* ```
*/
@Directive({
selector: 'input[type=radio][ngControl],input[type=radio][ngFormControl],input[type=radio][ngModel]',
host: {'(change)': 'onChange($event.target.value)', '(blur)': 'onTouched()'},
bindings: [RADIO_VALUE_ACCESSOR]
})
export class RadioControlValueAccessor implements ControlValueAccessor {
onChange = (_:any) => {} ;
onTouched = () => {};
constructor(private _renderer: Renderer, private _elementRef: ElementRef) {}
writeValue(value: any): void {
this._renderer.setElementProperty(this._elementRef.nativeElement, 'checked', value == this._elementRef.nativeElement.value);
}
registerOnChange(fn: (_: any) => {}): void { this.onChange = fn; }
registerOnTouched(fn: () => {}): void { this.onTouched = fn; }
}
Any idea how to fix this?
Or does RC2 include radio button binding in a way that I don't have to use external code? If so how?