Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何访问angularjs中返回的动态范围_Html_Angularjs_Dynamic Scope - Fatal编程技术网

Html 如何访问angularjs中返回的动态范围

Html 如何访问angularjs中返回的动态范围,html,angularjs,dynamic-scope,Html,Angularjs,Dynamic Scope,我有一个需求–单个angular js函数根据函数的一个输入参数动态返回范围变量。对于控制器函数,我找到了一些关于如何返回动态范围的示例,如 $scope[attributeId]=data.response;attributeId是一个输入参数,data.response是一个数组 问题是如何在HTML中使用这样的范围变量?我有一个像这样的选择控件,它将用范围中返回的值填充一个下拉列表,在这种情况下,什么应该被指定为model和option <button ng-click="getAt

我有一个需求–单个angular js函数根据函数的一个输入参数动态返回范围变量。对于控制器函数,我找到了一些关于如何返回动态范围的示例,如

$scope[attributeId]=data.response;attributeId是一个输入参数,data.response是一个数组

问题是如何在HTML中使用这样的范围变量?我有一个像这样的选择控件,它将用范围中返回的值填充一个下拉列表,在这种情况下,什么应该被指定为model和option

<button ng-click="getAttributeValue(getProductsModel,p.attributeId, $event)">Get Attribute Value</button>
<select data-ng-model="attributeModel" 
    data-ng-options="a for a in attributeResponse">
    <option value="">-- Select Value --</option>
</select>
举个例子会很有帮助。

您应该将其分配给$scope.attributeId。之后,可以使用ng options指令填充它

现在我不知道你们的数据结构是怎样的,所以这里有一个关于汽车的例子

虚拟阵列:

以及有人居住的汽车的元素:

<select ng-model="selectedOption" ng-options="car.name for car in cars">

现在,您可以使用$scope.selectedOption访问所选选项。

不完全如此。同一个函数将使用不同的输入多次调用,每次它将返回一个数组,其中包含需要持久化的不同数据。像$scope[101]、$scope[201]、$scope[301]这样的每个作用域都要绑定到不同的下拉列表。
<select ng-model="selectedOption" ng-options="car.name for car in cars">