search

Home  >  Q&A  >  body text

css - Angular2中怎么不通过路由实现多个button的切换效果?

如何不用路由实现点击按钮时,当前按钮背景颜色变成蓝色,其他按钮背景颜色任然是灰色的效果呢?

漂亮男人漂亮男人2744 days ago759

reply all(3)I'll reply

  • 黄舟

    黄舟2017-05-15 17:15:11

    You should ask and answer your own questions. This effect has been achieved through the ng2 command. For details, please see:
    http://tc9011.com/2017/03/03/...

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-15 17:15:11

    ng-class满足不了吗
        <p ng-class="{true: 'green', false: 'red'}[isA[0]]"></p>
        <p ng-class="{true: 'green', false: 'red'}[isA[1]]"></p>
    点击事件去修改isA数组

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-15 17:15:11

    After reading your blog post, although the principles are the same, I still feel that your approach may be complicated. Post it here for you to take a look :)

    The best practice I personally think is the solution that the angular-router module has provided us: the routerLinkActive directive.
    Click here for code sample

    That's all...

    reply
    0
  • Cancelreply