I have pretty complicated controller (about 3K rows of code) that demonstrates dashboard. Controller contains a lot of charts, grid tables, and so on.
For example I moved grid table logic to undermentioned directive named wmGridActionItems
. Notice, it uses parent scope:
app.directive('wmGridActionItems', ['$rootScope', '$timeout', function ($rootScope, $timeout) {
return {
restrict: 'E',
templateUrl: 'views/grid-action-items.html',
link: function (scope, elem, attrs) {
// logic goes here
}
};
}]);
and HTML:
<div ui-grid="gridActionItemsOptions"
ui-grid-auto-resize
ui-grid-pagination
ui-grid-selection
ui-grid-auto-resize
ui-grid-resize-columns>
</div>
So in main controller HTML i just write: <wm-grid-action-items></wm-grid-action-items>
I don't manage to use this directive in other places but at least I divide my BIG controller to several little directives that should help me to handle dashboard.
I do something wrong? Is it good practice? Has Angular other approaches to solve this issue?
EDIT
This is my $StateProvider
for dashboard view:
$stateProvider
.state('sidemenu.dash', {
url: '/dshmngr',
abstract: true,
views: {
'content': {
templateUrl: 'views/dashboard/dashboard_manager.html',
controller: 'DashboardMngrCtrl'
}
}
})
.state('sidemenu.dash.main', {
url: '/main',
views: {
'content': {
templateUrl: 'views/dashboard/dashboard-main.html',
controller: 'DashboardNewCtrl'
}
}
})
.state('sidemenu.dash.drill', {
url: '/drill/:type',
views: {
'content': {
templateUrl: 'views/dashboard/dashboard-tag-details.html',
controller: 'DashboardDetailedCtrl'
}
}
})
Thanks,