0

Right now I have existing productsController which delivers products data using dataService

myApp.controller("productsController", function ($scope, $http, dataService) { $scope.productsData = dataService; dataService.getProducts() .then(function () { //success }, function () { // error alert("could not load products"); }); }); 

this works fine, products are rendered on my view properly. Now I want to open product details on product click so I add

<tr ng-repeat="product in productsData.products"> <td>{{ product.Name }}</td> <td> <a ng-href="{{ product.Id }}"> <img ng-src="{{ product.thumbnail }}" width="50" height="50" /> </a> </td> </tr> 

I added corresponding route

myApp.config(function ($routeProvider) { ... .when("/product/:id", { controller: "productsController", templateUrl: "/templates/productDetailsView.html" }) ... } 

my question is: How can I pass this id parameter to productsController so I can pass it further to my data service which will return data.

1 Answer 1

4

Inject $routeParams into your controller.

myApp.controller("productsController", ['$routeParams', function ($routeParams) { console.log($routeParams.id); }]); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.