请参阅以下示例。我已经将jquery和jquery-steps加载到项目中了,而且它正在工作。但是,在呈现视图之后,更改输入框中的数据不会更新表单组mainForm中的值。我相信原因是jquery-steps动态地删除并重构了表单的html,因此表单组不再链接到DOMs。
在FormGroup重建html之后,是否有任何方法将jquery-steps mainForm重新绑定到DOMs上?
我读过关于ComponentResolver和ViewContainerRef的文章,它应该在那里使用吗?你能给我举个例子,在这种情况下如何使用?
谢谢!
<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();
}
}发布于 2016-11-16 06:18:47
这不起作用的主要原因是jquery插件删除了您的html标记。
在angular2中使用jquery是个坏主意,但是如果您想让它正常工作,我可以稍微修改一下库
jquery.steps.js
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())),另见柱塞实例
https://stackoverflow.com/questions/40582639
复制相似问题