我编写了一个指令,根据组合框的选择显示db到输入字段的值。请参阅以下代码。
html代码:
<table class="table">
<tr>
<td>
<select show-threshold id="ins_id" name="ins_id" ng-model="pic.ins_id" ng-options="insurance.ins_id as insurance.Ins_name for insurance in ins" required class="form-control">
<option value="">Choose PIC</option>
</select>
<div ng-if="pic_form.ins_id.$dirty && pic_form.ins_id.$invalid">
<small class="error" ng-if="pic_form.ins_id.$error.required">This field is required</small>
</div>
</td>
<td>
<input type="text" name="threshold" ng-model="pic.threshold" class="form-control" placeholder="Threshold value" required>
<div ng-if="pic_form.threshold.$dirty && pic_form.threshold.$invalid">
<small class="error" ng-if="pic_form.threshold.$error.required">Threshold is required</small>
</div>
</td>
</tr>
</table>
js code:
app.directive('showThreshold',function($http){
return{
restrict:'A',
link:function(scope,element,attr)
{
element.on("change",function(){
$http.get(site_url+"finance/getThreshold",{params:{ins_code:scope.pic.ins_id}}).success(function(data){
scope.pic.threshold=data.threshold;
});
});
}
}
});
在change()函数内部,我在更改选择框时获得了以前的模型值。如何在更改函数中获取更新的模型值?
实际上我需要 scope.pic.ins_id 的更新值,但它已经获得了之前选择的值。 任何帮助赞赏!