2017-02-26 92 views
6

在Firefox這plunker工作,任何控制檯錯誤,但在Chrome中我得到的消息:在formcontrol在Chrome角2.錯誤:無法找到未指定名稱屬性控制

<ul> 
    <li *ngFor="let item of data"> 
    <label> 
     <input type="radio" name="radio1" 
     [value]="item.id" 
     [formControl]="childControl" 
     (input)="fn($event.target.value)" > 
     <p>{{ item.title }}</p> 
    </label> 
    </li> 
</ul> 

錯誤

無法找到未指定名稱控制屬性

+0

代碼:[plunker](https://plnkr.co/edit/hkk0CANKWRmys9R4gZg1?p=preview) – MikeS

+0

我很抱歉。我的錯誤和不注意。 – MikeS

回答

3

既然你已經在你的MyChild你的模板指定[formControl]="childControl"ñ在你的MyChild類中指定一個FormControl。

export class MyChild implements ControlValueAccessor { 
    @Input() data: any; 
    out: any; 
    childControl = new FormControl(); 

    fn: (value:any) => void; 

    validateFn: any =() => {}; 

    constructor(private _renderer: Renderer, private _elementRef: ElementRef) {} 

    writeValue(value: any): void { 
    this._renderer.setElementProperty(this._elementRef, 'checked', value == this._elementRef.nativeElement.value); 
    } 
    registerOnChange(fn: (value: any) => void) { 
    this.onChange = fn; 
    } 
    registerOnTouched() {} 

} 

但是之後你結束了,這似乎是無關TypeError: v is not a function

0

我認爲你必須使用formControlName屬性爲輸入標籤,我希望這將有助於一個錯誤。

相關問題