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

时间:2017-07-10 15:00:17

标签: javascript angularjs

我有两个列表项Reciever a和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 =&#39; device&#39;

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

我们怎么能这样做?

1 个答案:

答案 0 :(得分:0)

这里需要一个选择输入。

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