I have specific viewing states that I want users to be able to link to.
I'm trying to route a controller to a specific state of the page when a user goes to http://localhost:3000/resource/#!/1
My configuration is:
$routeProvider.when('/:memberId', {
controller: 'MemberDetailsCtrl'
});
$locationProvider.html5Mode(false).hashPrefix('!');
I've been experimenting a lot and it seems like $route is undefined until all the scopes are done generating. That means I can't execute
$http.get('/resource/' + $route.current.params.memberId + '.json')
in the controller / service and trigger that particular state by checking the route params.
I've been able to do all of this using regex and $location.path()
inside my controller but maybe there's a better way? (using ngView is not flexible enough)
Nowadays there is a great module — ui-router which helps manage routes, states and views much better than default $routeProvider.
How about just setting up a watch function for the route change broadcast from within the controller:
$scope.$on('$routeChangeSuccess', function() {
$http.get('/resource/' + $scope.params.memberId +'.json').success(function (d) {$scope.jsresponse = d;});
});