2016-11-14 11 views
3

次の例を参照してください。私はすでにjqueryjquery-stepsをプロジェクトにロードしています。ただし、ビューのレンダリング後、入力ボックスのデータを変更しても、フォームグループmainFormの値は更新されません。その理由は、jquery-stepsがフォームのhtmlを動的に削除して再構成したため、フォームグループがDOMにリンクしていないと考えられます。Angular2のFormGroupでjquery-stepsを使用

jquery-stepsのhtmlを再構成した後に、フォームグループmainFormをDOMに再バインドする方法はありますか?

私は約ComponentResolverViewContainerRefを読んでいます、それはそれらを使うべきですか?このような状況でそれらを使用する方法の例を教えてください。

ありがとうございました!

<pre>{{ mainForm.value | json }}</pre> 

<form [formGroup]="mainForm" id="mainForm" action="#"> 
    <h1>Account</h1> 
    <div> 
     <label for="userName">User name *</label> 
     <input formControlName="userName" type="text" class="required"> 
     <label for="password">Password *</label> 
     <input formControlName="password" type="text" class="required"> 
     <label for="confirm">Confirm Password *</label> 
     <input formControlName="confirm" type="text" class="required"> 
     <p>(*) Mandatory</p> 
    </div> 
    <h1>Finish</h1> 
    < div> 
     <input formControlName="acceptTerms" type="checkbox" class="required"> 
     <label for="acceptTerms">I agree with the Terms and Conditions.</label> 
    </div> 
</form> 
import {Component, AfterContentInit} from "@angular/core"; 
import {FormBuilder, Validators, FormGroup} from "@angular/forms"; 

@Component({ 
    templateUrl: 'main-view.template.html' 
}) 
export class MainViewComponent implements AfterContentInit { 

    private mainForm: FormGroup; 

    constructor(private formBuilder: FormBuilder) { 
     this.mainForm = this.formBuilder.group({ 
      userName: ['', Validators.required], 
      password: ['', Validators.required], 
      confirm: ['', Validators.required], 
      acceptTerms: ['', Validators.required], 
     }); 
    } 

    ngAfterContentInit() { 
     $("#mainForm").steps(); 
    } 
} 

答えて

4

それが動作していない主な理由は、jqueryの-ステッププラグインは、あなたのHTMLマークアップを取り除くことです。 angular2にjqueryのを使用して

は悪い考えですが、あなたが働いて、それを取得したい場合、私はあなたが少しも

function render(wizard, options, state) { 
+ var contentWrapper = $('<{0} class=\"{1}\"></{0}>'.format(options.contentContainerTag, "content " + options.clearFixCssClass)); 
+ contentWrapper.append(wizard.children()); 
    // Create a content wrapper and copy HTML from the intial wizard structure 
    var wrapperTemplate = "<{0} class=\"{1}\">{2}</{0}>", 
     orientation = getValidEnumValue(stepsOrientation, options.stepsOrientation), 
     verticalCssClass = (orientation === stepsOrientation.vertical) ? " vertical" : "", 
-  //contentWrapper = $(wrapperTemplate.format(options.contentContainerTag, "content " + options.clearFixCssClass, wizard.html())), 

参照Plunker Exampleをライブラリに変更

jquery.steps.js提供することができます

+0

こんにちはyurzui ..私は厳密な条件を満たすまで続行ボタンを無効にする必要があります.exex:ユーザー名を入力せずにユーザーは続行を許可できません(ボタンを無効にする)。角度の文脈ではどうしたらいいですか?ありがとう – bews99

関連する問題