I am designing a tabular structure based cms in angularjs in which multiple articles can be opened and edited in tabs. I am using articleController for articles. For each article url parameters( mainly article id) are different.
I and trying to make these tabs sticky.
Following is the code I have written: Routes:
$urlRouterProvider.otherwise('/');
$urlRouterProvider.deferIntercept();
$stickyStateProvider.enableDebug(true);
//States definition for tabbed routes
$stateProvider.state('main', {
url: '/?ssoToken',
templateUrl: 'main.html',
controller: 'MainController',
abstract:true
}).state('main.dashboard', {
url: 'dashboard',
views: { 'dashboard@cmslite': { controller: 'DashboardController', templateUrl: 'dashboard.html'}},
sticky: true
}).state('main.article', {
url: 'article?id',
views: { 'article@cmslite': { controller: 'ArticleController', templateUrl: 'article_partial.html'}},
sticky: true
});
Maincontroller:-
$scope.tabData = [
{
heading: 'Dashboard',
route: 'cmslite.dashboard',
params:$scope.$routeParams,
view:'dashboard'
},
{
heading: 'Article',
route: 'cmslite.article',
params:$scope.$routeParams,
view:'article'
}
];
$scope.matchTabStates=function(tab){
if($state.includes(tab.route)){
if(Utils.arraysEqual(tab.params,$scope.$routeParams)){
return true;
}
}
return false;
};
main.html
<div ng-repeat="tab in tabData" ui-view="{{tab.view}}" ng-show="matchTabStates(tab)"></div>
DashboardController
//To add articles in tabs dynamically
$scope.editArticle = function(id,title){
var reqParam = {id: id, ssoToken: MainProperties.ssoToken};
if(id!=null && id!="") {
$scope.$parent.tabData.push({
heading: 'Article: ' + title,
route: 'cmslite.article',
params: reqParam,
view:'article'
}
);
}
};
So user can add new tab for editing different articles from tabs.
Problem in when there are more then one article in tabs sticky state doesn't work while switching tabs from one article to another because they are using the same controller. Any suggestions?