search

Home  >  Q&A  >  body text

javascript - Click to add and delete classes in angularJs

$(".task-aot>p").on("click", function () {
$(this).addClass('active').siblings().removeClass("active")
});
Can the effect of this code be realized in Angular?

曾经蜡笔没有小新曾经蜡笔没有小新2720 days ago799

reply all(2)I'll reply

  • 学习ing

    学习ing2017-06-08 11:04:15

    If it is angularjs (officially called angular1.0x version), there is an ngClass directive that can control whether the class value appears. The specific usage is as follows
    <p ng-class {'selected': isSelected, 'car': isCar}">
    </p>

    You can use an ng-click to control a value, and then map this value to ng-class for control

    reply
    0
  • 漂亮男人

    漂亮男人2017-06-08 11:04:15

    Wrong, you are asking a very common question in ng
    For example, the li in ul is traversed, and each li has an $index value
    Take a value such as target, the default is -1,
    When you click li , let the target be equal to the index value of the current li,
    The style judgment is roughly written like this, css: { selected: $index == target }

    reply
    0
  • Cancelreply