AngularJS: route to /page/:id and show id's information?
Use a different controller to simplify this. The parameter :id
can be accessed using $routeParams
injected into controller.
angular .module('swoleincApp') .controller('ProfileCtrl', ['$scope', '$http','$routeParams', ProfileCtrl]);function ProfileCtrl($scope, $http, $routeParams) { $http.get('storage/models.json').success(function(data) { $scope.profile= data[$routeParams.id]; });}
Be sure to update your routing config for this controller.
Normally you would create a service to handle retrieving the data and storing it. Have left $http
in for now to keep it simple.
Suggest going through the phoneCat tutorial on documentations site.Here's link to the routing section
All you need to do is to use the $RouteParams
service. Here's the documentation on the AngularJS official website