Answer the question
In order to leave comments, you need to log in
How to make a tab app in angularjs?
The application consists of several tabs that are added at startup or during operation.
The user should be able to switch between tabs and come back at any time.
Tabs contain a bunch of views with a hard-to-identify state. For example, a form to fill out, or a table of query results with selections.
As far as I understand, ui-router, sticky states, deep state redirect will not cope with this, and you need to store the state directly in the DOM and its associated controllers. And do the tabs themselves in the spirit of ui-bootstrap, through the tabset/tab directives or by hand through ng-show.
The question is how to create tabs with nested views in this case?
And how to create them from controllers nested inside tabs?
Upd.Generally, if I do something like
<tabset>
<tab ng-repeat="tab in ctrl.tabs"><ng-include src="tab.src"></tab>
</tabset>
.service('TabService', function() {
this.tabs = []; /* все вкладки приложения */
this.openTab = function() { ... };
this.closeTab = function() { ... };
})
.controller('TabsCtrl', function TabCtrl(TabService) {
this.tabs = TabService.tabs; /* чтобы сделать ng-repeat */
this.openTab = TabService.openTab; /* чтобы сделать где-нибудь ng-click="ctrl.openTab()" */
})
<tab ng-repeat="tab in ctrl.tabs"><ng-include src="tab.src"></tab>
Answer the question
In order to leave comments, you need to log in
Working code: plnkr.co/edit/lnijKg?p=info
Idea:
* Use ng-repeat to render tabs
* Use ui-router to bind states to tabs and directives with their content
* Ignore ui-view, and controllers with templates
* Intercept state transitions to switch tabs from the service.
* Insert content using a smart-ass recompile proxy directive.
As far as I understand, ui-router, sticky states, deep state redirect will not cope with this
controllerProvider: function($stateParams) {
var ctrlName = "Controller" + $stateParams.tab;
return ctrlName;
}
app
.controller('Controller1', function(){})
.controller('Controller2', function(){})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question