2016-12-05 44 views
3

我開始用角2,我目前使用的版本2.2.2角2單選按鈕不反應形式

我寫一個反應形式正確初始化,但我不能初始化選中的單選按鈕。頁面應該加載一個單選按鈕,但這不會發生。

我一直無法找到問題的根源。從Web上的代碼示例中,我認爲這應該起作用。這是我的代碼片段。

<form [formGroup]="consultaSolicitudesINETELForm" (ngSubmit)="consulta(consultaSolicitudesINETELForm)"> 
<input type="radio" formControlName="criterio" value="1" /> 
<input type="radio" formControlName="criterio" value="2" /> 
<input type="radio" formControlName="criterio" value="3" /> 
<input type="text" formControlName="folio" placeholder="folio" required> 
</form> 

該組件

import { Component, OnInit } from '@angular/core'; 
import { FormGroup, FormBuilder, Validators } from '@angular/forms'; 
@Component({ 
moduleId: module.id, 
selector: 'my', 
templateUrl: 'my.component.html', 
styleUrls: ['my.component.css'] 
}) 
export class My implements OnInit { 

myForm: FormGroup; 

constructor(private fb: FormBuilder) { 

} 

ngOnInit(): void { 
    this.buildForm(); 
} 

buildForm(): void { 

    this.consultaSolicitudesINETELForm = this.fb.group({ 
    criterio: ["2"], 
    folio: ["TEST"], 

    }); 

    this.myForm.valueChanges.subscribe(data => this.onValueChanged(data)); 
    this.onValueChanged(); 

} 

編輯: Hereplnkr我從那裏我補充說,沒有在我的環境中運行無線電爲例分叉。我看到的唯一區別是版本號。

編輯2: 好的,我發現它與ng-bootstrap有關。如果我使用NgbModule.forRoot(),那麼單選按鈕沒有初始化,並且不按預期工作,如果我禁用了ng-bootstrap,那麼它們工作,但是因爲我在其他地方使用了ng-bootstrap,我不能這麼做。

我使用ng-bootstrap自己的單選按鈕組和重新設計網頁來繞過它。我將單選按鈕放置在各種字段集的圖例中,並且所有內容始終可見。 現在無線電的工作方式類似於選項卡,根據當前選擇顯示不同的div。

單選按鈕的原始聲明是選擇一個工作的字段集,其中所有的元素將被啓用,並且所有其他字段集的內容都被禁用。

+0

您的收音機也應該有相同的名稱。 – Milad

回答

1

這個問題是與NG-引導和https://github.com/ng-bootstrap/ng-bootstrap/issues/1125

這是高優先級對他們進行跟蹤。

+0

我正面臨類似的問題。能否請你幫忙? https://stackoverflow.com/questions/47388377/two-way-binding-not-working-in-ng-bootstrap-radio-button-in-an-angular-reactive/47388971#47388971 – codejunkie