如何仅为angularjs中的活动按钮获取ng-model值
<div class="time_buttons mar_bot_30" ng-init="selectedBtn = 'minute'">
<button class="btn btn-default" ng-class="{'active':selectedBtn === 'second'}" ng-click="selectedBtn = 'second'" ng-model="SECOND">Second</button>
<button class="btn btn-default" ng-class="{'active':selectedBtn === 'minute'}" ng-click="selectedBtn = 'minute'" ng-model="MINUTE">Minute</button>
<button class="btn btn-default" ng-class="{'active':selectedBtn === 'hour'}" ng-click="selectedBtn = 'hour'" ng-model="HOUR">Hour</button>
</div>
谢谢....
答案 0 :(得分:1)
<div class="time_buttons mar_bot_30">
<button class="btn btn-default" ng-class="{'active':selectedBtn === 'second'}" ng-click="selectedButton('Second')">Second</button>
<button class="btn btn-default" ng-class="{'active':selectedBtn === 'minute'}" ng-click="selectedButton('Minute')" >Minute</button>
<button class="btn btn-default" ng-class="{'active':selectedBtn === 'hour'}" ng-click="selectedButton('Hour')">Hour</button>
</div>
JS
$scope.selectedBtn = 'minute'
$scope.selectedButton = function(status) {
console.log(status)
}
你需要在ng-click中调用一些函数并传递参数。不需要在按钮中使用ng-model。
这里selectedBtn将给出默认值,点击selectedButton函数后会调用并给出你选择的值
答案 1 :(得分:0)