Austin N Austin N - 1 year ago 242
AngularJS Question

[Angular JS]- Tabs Pane Example - Dynamic Add Tab

I have used the example from Angular JS Homepage and modified it to meet the requirements.

I have added the tabs info in a scope array and manipulate the data based in some conditions.


  1. I have attached an ng-bind on tabItem.title, so any change in the text box will update the title, but i want to limit the displaying of the title by 10 chars

  2. When i create a new tab, i want that tab to be the selected one.

  3. How can i select a tab based on some action taken (like on a click move from tab 1 to tab 2)


<div ng-cloak ng-app="TabsApp">
<div class="container" ng-controller="TabManagerCtrl">
<span class="label label-info label-ext" ng-click="tabManager.addTab()" style="cursor:pointer">Add a Tab</span><br/><br/>

<div tabs>
<div ng-repeat="tabInfo in tabManager.tabItems" pane title="{{ tabInfo.title }}">
<p>{{ tabInfo.content }}</p>
<input type="text" ng-model="tabInfo.title" ng-change="tabManager.getTitle(tabInfo)">


</div><!-- /container -->
</div> <!-- /container -->
</div> <!-- /app -->

Answer Source

that's strange... The limitTo filter doesn't seem to work, but you can create a new one and change your line

<div ng-repeat="tabInfo in tabManager.tabItems" pane title="{{ tabInfo.title }}">


<div ng-repeat="tabInfo in tabManager.tabItems" pane title="{{ tabInfo.title | limit:10}}">


angularApp.filter('limit', function() {
    return function (input, value) {
        return input.substr(0,value);

For the select one, I think it doesn't work because you have to have access to the pane scope. One way to do it is to access to access the property from the pane when you create it. In the pane directive, just add :


just after the tabsCtrl.addPane(scope); line. But then you also have to change the tabs directive so that the line

$ = function(pane) {

become = $ = function(pane) {

For your 3rd question, I don't know how to do it in that scheme.

I would make the pane directive different, putting the select function out of the directive, and binding it directly to your tabManager object. Like this : In this cas, you have the 3 requirements, and you can select the tab from ouside by calling

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download