Angularjs 角度-将两个选定ng模型值合并为一个

Angularjs 角度-将两个选定ng模型值合并为一个,angularjs,angular-ngmodel,Angularjs,Angular Ngmodel,我是新来的,所以非常感谢大家的帮助。我有两个选择下拉列表,我需要将它们组合成一个值并指定给cusPro.height。这是这样工作的: <select class="form-control" name="height" ng-model="cusPro.height"> <option value="3">3</option> <option value="4">4</option> etc... <select ng-mod

我是新来的,所以非常感谢大家的帮助。我有两个选择下拉列表,我需要将它们组合成一个值并指定给cusPro.height。这是这样工作的:

<select class="form-control" name="height" ng-model="cusPro.height">
<option value="3">3</option>
<option value="4">4</option>
etc...
<select ng-model="cusPro.feet" ng-options="feetLength for feetLength in feetLengths">
<select ng-model="cusPro.inches" ng-options="inchesLength for inchesLengthin inchesLengths">

You selected: {{cusPro.feet}} feet, {{cusPro.inches}} inches

3.
4.
等
但我想这样做:

<select class="form-control" name="height_ft" ng-model="feet">
    <option value="3">3</option>
    <option value="4">4</option>
    etc...
<select class="form-control" name="height_in" ng-model="inches">
    <option value="3">3</option>
    <option value="4">4</option>
    etc...

3.
4.
等
3.
4.
等
我试着把
cusPro.height=feet+'\''+'\''+'\''''\''';
放进去,得到了:

referenceError:未定义cusPro


首先,Angular用自己的实现覆盖
select
指令,该指令不需要多个
选项
标记。请详细阅读该指令的工作原理

然后,您的HTML将如下所示:

<select class="form-control" name="height" ng-model="cusPro.height">
<option value="3">3</option>
<option value="4">4</option>
etc...
<select ng-model="cusPro.feet" ng-options="feetLength for feetLength in feetLengths">
<select ng-model="cusPro.inches" ng-options="inchesLength for inchesLengthin inchesLengths">

You selected: {{cusPro.feet}} feet, {{cusPro.inches}} inches

您选择:{{cusPro.feet}}英尺,{{{cusPro.inches}}英寸

在您的
控制器中

$scope.feet = []; // Your data
$scope.inches = []; // Your data

// Merge data
$scope.displayedData = $scope.fee.concat($scope.inches);
视图中

<select class="form-control" name="height_ft" ng-model="displayedData">
    <option value="3">3</option>
    <option value="4">4</option>

3.
4.

你可以考虑显示你的NG模型代码……你尝试在哪里设置“代码> CuPro?身高< /代码>?如果它在你的控制器里面,你可能忘记把<代码>这个< /代码>分配给一个名为<代码> CuSpPro < /代码>的变量。