angularjs - Accessing parameter from Angular route -


i working on first production angular application. know can set routing can grab parameter , use to, instance, data database.

for instance, in application have list of cases. each case has case number. have partial displays documents related case. here routing:

jbenchapp.config(['$routeprovider', '$locationprovider',    function($routeprovider, $locationprovider) {       $routeprovider.         when('/dashboard', {             templateurl: 'partials/dashboard.html',             controller: 'jbenchctrl'         }).         when('/calendar', {             templateurl: 'partials/calendar.html',             controller: 'jbenchctrl'         }).         when('/', {             templateurl: 'partials/calendar.html',             controller: 'jbenchctrl'         }).         when('/case/:number', {             templateurl: 'partials/case.html',             controller: 'casedetailctrl'         }).         otherwise({             redirectto: '/'         });        $locationprovider.html5mode(true);   }]); 

if want documents case #11151 , craft url "/case/11151" how grab 11151 , pass function can data? example, believe need controller:

jbenchapp.controller('casedetailctrl', ['$scope',   function ($scope) {       // call service returns json       $scope.casedocs = data;   }]); 

can point me in right direction?

you need inject routeparams in controller. update controller following

jbenchapp.controller('casedetailctrl', ['$scope', '$routeparams',   function ($scope, $routeparams) {       console.log($routeparams.number); // retrieve route parameters       // call service returns json       $scope.casedocs = data;   }]); 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -