javascript - How to use an URL param in a templateUrl using ngRoute? -
i building angularjs app, app.js looks this. however, throws unknown provider: $routeparams
error. idea why?
var angularsite = angular.module('angularsite', [ 'ui.router', 'ngroute', 'sitecontroller', 'sitedirectives' ]) .config(['$routeprovider', '$routeparams', function($routeprovider,$routeparams) { $routeprovider. when('/projects', { templateurl: 'partials/projects.html', controller: 'projectcontroller' }). when('/projects/:projectid', { template: 'partials/pages/'+$routeparams.projectid+'.html', controller: 'projectdetailcontroller' }). otherwise({ redirectto: '/about' }); }]);
$routeparams
service , can not injected in .config
.
if want set templateurl url params, correct way use function set templateurl
(as following):
.when('/projects/:projectid', { templateurl: function(params) { // <-- return 'partials/pages/' + params.projectid + '.html' }, controller: 'projectdetailcontroller' })
Comments
Post a Comment