In a single-page Angular app, I have a controller that acts as a tab handler for 3 screens:
app.controller('tabCtrl', function ($scope, getName) {
$scope.tabs = {
issue_list: {'id': 'issue_list', 'title': 'Issues reported'},
issue_report: {'id': 'issue_report', 'title': 'Report issue'},
user_prefs: {'id': 'user_prefs', 'title': 'Your preferences'}
};
$scope.tab = $scope.tabs.issue_list;
$scope.activate = function(myid) {
if (myid in $scope.tabs) {
$scope.tab = $scope.tabs[myid];
}
};
});
Since I need to activate one of the tabs after a user successfully submits data via another controller:
app.controller('issueCtrl', function ($scope, $http, server, getName) {
//lots of data-server stuff here
});
Because it's going to be needed from various places, I was about to rewrite 'tabCtrl
' as a service
, to avoid the whole calling one controller from another thing. But in the meantime I just called both controllers from one click:
<button id="raise" ng-click="addIssue();activate('issue_list')" type="button">send now</button>
Is this acceptable AngularJS practice? Seems a little clunky, but I'm new to Angular, have deadlines, and this 'just works'.