如何将ng-model添加到角度js中的下拉列表中



>我有两个列表项的下拉列表 Reciever aand beacon.

<ul class="dropdown-menu filter-state">
<li ng-class="{active:filterState === 'Receiver'}">
<a href="" ng-click="updateFilterState('Receiver')">Receiver</a>
</li>
<li ng-class="{active:filterState === 'Beacon'}">
<a href="" ng-click="updateFilterState('Beacon')">Beacon</a>
</li>
</ul>

默认情况下,选定的下拉项是第一个接收者,但我想向其添加 ng-model 以保持它的状态。

我希望这个 $scope.device 默认显示为 ng-model= 'device'

$scope.$onMessage(Message.deviceType,function(event,deviceType){
$scope.device=deviceType;
});

我们该怎么做呢?

您需要在此处选择输入。

<select name="devicetype" ng-model="filterState">
<option value="Receiver" ng-class="{active:filterState === 'Receiver'}"> Receiver </option>
<option value="Beacon" ng-class="{active:filterState === 'Beacon'}">Beacon</option>
</select>

最新更新