我无法找到如何检索用户使用angular2形式修改的所有字段。我在这里做了一些研究,并在angular2官方形式的文档,我找不到这样的信息。如何使用angular2形式获得所有“脏”(修改)字段?
这是它使用jQuery我该怎么办:
this.isFormDirty = function (form) {
var changeNames = [];
$(form).find(":input:not(:button):not([type=hidden])").each(function() {
if ((this.type == "text" || this.type == "textarea" || this.type == "number" || this.type == "hidden" || this.type == "file") && this.defaultValue != this.value) {
changeNames.push(this.name);
} else {
if ((this.type == "radio" || this.type == "checkbox") && this.defaultChecked != this.checked) {
changeNames.push(this.name);
} else {
if ((this.type == "select-one" || this.type == "select-multiple")) {
for (var x = 0; x < this.length; x++) {
if (this.options[x].selected != this.options[x].defaultSelected) {
changeNames.push(this.name);
}
}
}
}
}
});
return changeNames;
};
有没有办法做到这一点使用angular2形式?我以为我会有某种changedValues属性,但我找不到它。
编辑
这是我的表单是如何创建的:(permissionForm的类型是FormGroup的)
this.permissionForm = this.fb.group({
FullUrl: ['', Validators.required],
Area: ['', Validators.required],
Controller: ['', Validators.required],
Action: ['', Validators.required],
Name: ['', Validators.required],
Description: ['', Validators.required],
ParentPermissionId: ['', Validators.required],
ShowInMenu: ['', Validators.required],
Order: ['', Validators.required],
Icon: ['', Validators.required]
});
This can help http://stackoverflow.com/questions/34615425/how-to-watch-for-form-changes-in-angular-2 – Drew13
'this.permissionForm.get('FullUrl')。dirty' ? – soywod
@ Drew13会调查它,谢谢:) – eestein