<div ng-app ng-controller="MyCtrl">
<select ng-model="referral.organization" ng-options="b for b in organizations"></select>
</div>
<script type='text/javascript'>
function MyCtrl($scope) {
$scope.organizations = ['Moo Milk','Silver Dairy'];
$scope.referral = {
organization: $scope.organizations[0]
};
}
</script>
<input name="job_description" onkeypress="return event.keyCode != 13;" ng-model="req_data.job_description" value="{{referral}}" placeholder="Quantity" type="text" />
这是我的代码我只想将选项值传递给输入ng-model。
答案 0 :(得分:0)
如果我理解正确,您希望在上面的下拉列表中选择的内容填充在下面的输入字段中吗?
<div ng-app ng-controller="MyCtrl">
<select ng-model="referral.organization" ng-options="b for b in organizations"></select>
<input name="job_description" onkeypress="return event.keyCode != 13;" ng-model="req_data.job_description" ng-value="referral.organization[0]" placeholder="Quantity" type="text" />
</div>
<script type='text/javascript'>
function MyCtrl($scope) {
$scope.organizations = ['Moo Milk','Silver Dairy'];
$scope.referral = {
organization: $scope.organizations[0]
};
}
</script>
试试这个,请务必将select
和input
放在与上面相同的控制器中。