I have two divs
that I'm trying to switch into an active inactive state, changing class
, and I need to use ng-click
with ng-class
. This basic code snippet is perfect for what I need, but I'm not sure how it's supposed to translate with ng-click
and ng-class
in the controller
.
我有两个div,我试图切换到一个活跃的不活跃状态,改变类,我需要使用ng-click与ng类。这个基本的代码片段非常适合我所需要的,但是我不确定它应该如何在控制器中使用ng-click和ng类进行转换。
$('button').on('click', function(){
$('button').removeClass('selected');
$(this).addClass('selected');
I pretty much have to use ng-click
and ng-class
to do this (don't ask). Any ideas?
我必须使用ng-click和ng类来完成这个(不要问)。什么好主意吗?
1 个解决方案
#1
1
<button ng-click="selected=!selected">button</button>
<div ng-class="{selected: selected}">div</div>
#1
1
<button ng-click="selected=!selected">button</button>
<div ng-class="{selected: selected}">div</div>