我有一个下拉菜单和切换下拉菜单的可点击元素。当用户单击下拉菜单中的列表项时,我想将该值添加到输入框值中。
我拥有的下拉菜单被迭代定义的次数以创建一个列出递增数字的下拉菜单。
<!--input-->
<input type="text" value="{{rooms}}">
<!--dropdown-->
<ul role="menu">
<li data-ng-repeat="i in getNumber(num_of_rooms)">
<a href="javascript:void(0);" data-ng-click="addToDropDown($index)">{{$index+1}}</a>
</li>
</ul>
//This function simply returns an array so the dropdown menu repeats a defined number of times
$scope.getNumber = function(n) {
return new Array(n);
};
//I want this scope function to add the value to the input by updating a scope variable
$scope.addToDropDown = function(scope_name, value){
$scope.scope_name = value;
};
-----------
//This works but I'm defining a scope name which I would like to add dynamically as I have multiple dropdown menus
$scope.addToDropDown = function(value){
var val = value+1;
$scope.rooms = val;
};
有没有办法为视图本身的范围变量分配一个新值?