angularjs - Angular $routeParams - mix a parameter and text? -
i'd have routes such this:
/products/1-bananas /products/2-apples /products/3-oranges ... /products/25-television /products/26-router is possible mix parameter id text together? utilize in way grab productid on pageload, , query database relevant information.
i know way (that works) this:
/products/1/bananas which designed route so:
/products/:productid/:productname but sense first way, id , name in same string, , separated dash, looks much cleaner.
any ideas on how accomplish this?
i caution avoid inventing new patterns , using them on existing ones. while may sense hyphen more readable, angular routes based on restful design principles. established pattern, resource/id/relation, more scalable , understandable. can imagine how scenario out of hand when starting introducing additional types of apples or tvs, or different manufacturers , farmers.
if insist on specified approach, can set routes , resources this:
.when('/products/:id-:name', { templateurl: '/assets/angular/templates/products.html', controller: 'productctrl' }) and
.factory('product', ['$resource', function($resource) { homecoming $resource('/products/:id-:name', {}); } ]) the hyphen character, has no special meaning can utilize it. should able @ route params way wish.
angularjs angular-routing
No comments:
Post a Comment