wesbos wesbos - 5 months ago 18
AngularJS Question

Angular $routeParams is blank

I have a really simple Angular app that I've distilled to the following:

var napp = angular.module('Napp',['ngResource']);

var CompanyCtrl = function($scope, $routeParams, $location, $resource) {
console.log($routeParams);
};


napp.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/company/edit/:id',
{templateUrl: '/partials/edit', controller: 'CompanyCtrl'}
);
}]);


and the HTML:

<div ng-controller="CompanyCtrl"></div>


When I log $routeParams, it comes up blank. When I use .otherwise(), it will load whatever I've specified there. Any idea what I'm missing?

Answer

First of all try this with

$locationProvider.html5Mode(true);

That should fix your starting code. Then adjust your code to support non-pushState browsers.

Hope this helps!