如何将输入选项赋值给输入ng-model

时间:2016-07-19 06:28:13

标签: javascript angularjs

<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。

1 个答案:

答案 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>

试试这个,请务必将selectinput放在与上面相同的控制器中。