Update: Here's a useful solution to the query posed in this post about improving optional function parameters in Javascript, available at this link.
Below is my controller setup:
.controller("NavTabController", ['TabService', function(TabService) {
var self = this;
self.switchTab = function(currentTab, dropDown) {
TabService.switchTab(currentTab, dropDown);
}
}])
and here is the factory structure:
.factory("TabService", [function() {
var tab = "home";
return {
switchTab: function(currentTab, dropDown) {
tab = currentTab;
}
}
}])
In the HTML snippet provided, you will find the following code:
<a href="#" ng-click="ctrl.switchTab('home')">Home</a>
<a href="#" ng-click="ctrl.switchTab('home', 'middle')">Optional</a>
It can be observed that the dropDown parameter is optional and may not always be included.
Given this scenario, what would be the best practice for incorporating an optional parameter in an AngularJS function?