I am creating a single page application that shows a table of data on the page. Along the top are several tabs that, when clicked, change the data that is loaded in the page. I would like to make each tab have a unique URL so it can be bookmarked.
Currently I am using Angularjs routes to accomplish this. Basically the route is defined as follows:
Route:
$routeProvider.
when('/staticURL/:urlParam', {
templateUrl: "/partials/table.html",
controller: 'TableDataCtrl'
}).
otherwise({
redirectTo: '/staticURL/data1'
});
Controller:
appControllers.controller('TableDataCtrl', ['$scope', '$routeParams',
function ($scope, $routeParams) {
var thisDrivesData = $routeParams.urlParam;
//Use loaded url parameter to pull back data
//from the server and update $scope.
}]);
The :urlParam is what tells the controller what data to load into the html table. The html table is held in a partial html file that is pointed to by the templateURL.
The problem with this solution is the HTML is not changing. It is only the data that needs to be re-loaded into the page. It would seem to me there must be a way of keeping the :urlParam to drive the controller but only change the data the controller is using. I also see no need to have a partial html file other than to make routing work. I do notice that the HTML is not being reloaded every time so that is good, but I still am not a fan of needing a separate html file to make this work.
Is there a better way to be using routing? Should routing not be used in this case? If not, what is the recommended way to have angular handle this?
ng-viewfrom you index.html, and removetemplateUrlfrom your route config.