私はこのソリューションをラジオボタンバインディングに使用しました。Angular2 - Radio Button BindingそれはRC1の下でうまくいった。角2 RC2ラジオボタンのバインディングが壊れています
しかし、私はAngular2 RC2にアップグレードしました。コンパイルエラーがあります
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...'.
コードは次のとおりです。
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; }
}
これを修正する方法はありますか?
またはRC2には外部コードを使用する必要がない方法でラジオボタンバインディングが含まれていますか?もしそうなら、どのように?
バインディングが存在する場合、なぜそれが動作を停止しましたか?どうか説明してくれますか? – Shawn
radiovalueaccesorを配列ではなく単純なオブジェクトとして渡そうとします – AngJobs
'bindings:[RADIO_VALUE_ACCESSOR]'を 'bindings:{obj:RADIO_VALUE_ACCESSOR}'に変更することを意味しますか?多分私はあなたを誤解しますか? – Shawn