【发布时间】:2018-12-05 12:23:14
【问题描述】:
我有几个字段的表单,但所有字段都存在于表单对象中,并且名称为扇区的字段不存在。为什么?我应该如何解决它?
<form name="candidateForm" ng-submit="submitForm()">
<div class="item item-top">
<label>{{'Company'|translate}}*</label>
<input company-autocompleter class="companyAutocompleterOuterSelect"
ng-maxlength="100" name="company" ng-model="candidate.company"
type="text" ng-change="progressUpdate()" required>
<div class="alert alert-danger"
ng-show="candidateForm.company.$invalid && !candidateForm.company.$pristine && candidateForm.company.$error.required == true">
{{'Enter a company'|translate}}
</div>
</div>
<div class="item industry">
<label>{{'Sector'|translate}}*</label>
<input sector-autocomplete name="sector" type="text"
class="select2-container form-control input-lg select2 select14 widthSelectInput1"
required>
<div class="alert alert-danger"
ng-show="candidateForm.sector.$invalid && !candidateForm.sector.$pristine && candidateForm.sector.$error.required">
{{'Enter a sector'|translate}}
</div>
</div>
</form>
因此,现场公司存在于对象中,但部门不存在
我没有使用 ng-model,因为扇区设置在指令内部:
element.select2({
minimumInputLength: 0,
placeholder: $translate.instant('Sector'),
allowClear: true,
data: translatedSectors,
dropdownCssClass: "bigdrop"
}).unbind("change").on("change", function(e) {
if(e.added) {
if($scope.candidate) {
$scope.candidate.sector = e.added.id;
$scope.progressUpdate();
} else {
if($scope.client) {
$scope.client.sector = e.added.id;
}
}
} else {
if($scope.candidate) {
$scope.candidate.sector = '';
} else {
if($scope.client) {
$scope.client.sector = '';
}
}
}
})
【问题讨论】:
-
您的公司输入中有 ng-model 属性,但您的部门输入中没有
-
如果您的意思是候选对象没有扇区属性。然后分享您的代码如何将数据填充到候选对象中
-
更新问题
标签: angularjs angularjs-directive angularjs-ng-model