Attempting to customize the standard user module of MeanJS, I added a new route:
state('users', {
url: '/users/:username',
templateUrl: 'modules/users/views/view-profile.client.view.html'
});
In my view:
data-ng-controller="ViewProfileController" data-ng-init="findUser()"
I also included $stateParams in my controller. However, when I try to access the username parameter in my ViewProfileController
using the findUser
function like this:
console.log($stateParams.username)
It returns undefined
.
When I adjust the route as follows:
state('users', {
url: '/users/:username',
template: function ($stateParams){
return $stateParams.username;
}
});
The username is correctly returned. I'm unsure what might be missing or incorrect. Any suggestions?
Edit: Below is my complete controller code
'use strict';
angular.module('users').controller('ViewProfileController', ['$scope', '$http', '$stateParams', '$location', 'Users', 'Authentication',
function($scope, $http, $location, Users, Authentication, $stateParams) {
$scope.user = Authentication.user;
$scope.findUser = function () {
console.log($stateParams);
...
};
}
]);