• All geek questions in one place

    Boot tabs with AngularJS

    I have problem using bootstrap tabs in AngularJS.

    <div class="tab-container"> <ul class="nav nav-tabs"> <li class="active"><a href="#home" data-toggle="tab">Home</a></li> <li><a href="#profile" data-toggle="tab">Profile</a></li> <li><a href="#messages" data-toggle="tab">Messages</a></li> </ul> <div class="tab-content"> <div class="tab-pane active cont" id="home"> <h3 class="hthin">Basic Tabs</h3> <p>This is an example of tabs </p> </div> <div class="tab-pane cont" id="profile"> <h2>Typography</h2> <p>This is just an example of content </div> <div class="tab-pane" id="messages">..sdfsdfsfsdf. </div> </div> </div> 

    The problem is that when I select a tab, for example "Home" or "Profile", I am redirected to / home or / profile url, and not showing the contents of the tab itself.

    I get the feeling that this can be somehow achieved with the directive and prevent redirection to the home page or page profile, rather than showing the contents of the tab.

    +6
    angularjs angularjs-directive
    David dury Nov 10 '14 at 12:56
    source share
    4 answers

    You can try using the Angular UI bootstrap boot components located here, http://angular-ui.imtqy.com/bootstrap/

    +5
    Richard Edwards Nov 10 '14 at 13:00
    source share

    replace href with data-target .

     <li class="active"><a data-target="#home" data-toggle="tab" >Home</a></li> 
    +39
    Rej Feb 20 '17 at 13:43
    source share

    A directive can help you deal with it.

     app.directive('showTab', function () { return { link: function (scope, element, attrs) { element.click(function (e) { e.preventDefault(); jQuery(element).tab('show'); }); } }; }); <a show-tab href="#tab_1"> Tab 1 </a> 

    A source

    +7
    Xyroid Jun 21 '16 at 11:47
    source share

    this code will solve the problem when using Angularjs

     <div class="tabbable tabs-below" ng-init="selectedTab = 1;"> <ul class="nav nav-tabs nav-justified"> <li ng-class="{active: selectedTab == 1}"> <a href="#" ng-click="selectedTab = 1;">Personal</a> </li> <li ng-class="{active: selectedTab == 2}"> <a href="#" ng-click="selectedTab = 2;">Education</a> </li> <li ng-class="{active: selectedTab == 3}"> <a href="#" ng-click="selectedTab = 3;">Contact</a> </li> </ul> <div class="tab-content" ng-show="selectedTab == 1"> 1. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </div> <div class="tab-content" ng-show="selectedTab == 2"> 2. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </div> <div class="tab-content" ng-show="selectedTab == 3"> 3. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </div> </div> 
    +5
    Msh Apr 17 '17 at 5:00
    source share

    Source: https://habr.com/ru/post/977980/

    More articles:

    • Is it enough to provide a 3x image only for all versions on the iPhone? - ios
    • Using SQLite-Net Extensions and OneToMany Relationships - c #
    • Logging via log4net for TextWriter shipped at runtime - c #
    • When will Firefox support HTML5 input type = date? - html5
    • Returns all the relevant elements of an array of objects? - javascript
    • use of specialized specialization - c ++
    • Facebook Share - Missing Texts - android
    • Postgresql 9.3 on Centos 7 with custom PGDATA - linux
    • Contravariance in abstract classes - c ++
    • Class NotFoundException in android.util.ArrayMap inside Intent - java

    All Articles

    Geek Questions | 2019