Can't Toggle Navbar in Bootstrap 4 in Angular

前端 未结 10 2635
借酒劲吻你
借酒劲吻你 2020-12-14 00:42

Why i can\'t toggle navbar when resizing to mobile screen in angular 4 using bootstrap 4. I included it in the angular cli in script and styles, the node modules from bootst

10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 01:23

    to make toggle working in angular, you have to do only 4 things

    1. install ng boostrap
    2. add toggle click listener to navbar switch (click)="isCollapsed = !isCollapsed"
    3. use property bind to aria-expanded, [attr.aria-expanded]="!isCollapsed" so that property will be changed when you click(either true or false)
    4. the same way use property bind to ngCollapse [ngbCollapse]="isCollapsed"

    NB: using JQuery is not adviced

    Collapse nav bar without using JQuery

提交回复
热议问题