javascript - passing route parameter to controller -
right have existing productscontroller delivers products info 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 rendered on view properly. want open product details on product click 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 pass id parameter productscontroller so can pass farther info service homecoming data.
inject $routeparams
controller.
myapp.controller("productscontroller", ['$routeparams', function ($routeparams) { console.log($routeparams.id); }]);
javascript angularjs
No comments:
Post a Comment