I am currently working on a page that displays all usernames, and when I click on a username, I want to retrieve more information from the server and display it on a separate User page (including first name, last name, etc).
However, I am encountering an issue where the fields are not populated when I click on a username. Can someone please review my code and advise on what might be going wrong?
app.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl : "pages/login_page.html"
})
.when("/userpage", {
controller : 'UserController',
templateUrl : "pages/user_page.html"
})
.when("/allusers", {
controller : 'AllUserController',
templateUrl : "pages/all_users.html"
});
});
This is my login code. After a user is authenticated, they can view all other users by changing the view to #allusers
.
app.directive("loginForm", function (AuthorizedHttp, ConfigurationRepository, UserObj) {
return {
restrict: 'E',
scope: {
},
templateUrl: 'templates/login-template.html',
replace: 'true',
controller: ['$scope', '$http', '$window',
function($scope, $location, $window) {
$scope.loginError = false;
$scope.login = function () {
// Code for logging in
}
}
]
}
});
The following code is responsible for retrieving all users
and works correctly.
app.controller('AllUserController', function ($scope, AuthorizedHttp, ConfigurationRepository, UserObj, UserCurrent, TimezoneService) {
$scope.init = function () {
// Code for initializing
};
});
Here's the HTML that displays all usernames and allows users to click on them to retrieve necessary information:
<div ng-controller="AllUserController" ng-init="init()">
<div ng-controller="UserController">
<div ng-repeat="email in users_emails" class="item-unchecked">
<a ng-click="getUser(email)">{{email}}</a>
</div>
</div>
</div>
The User controller is executed every time a username link is clicked:
app.controller('UserController', function ($scope, AuthorizedHttp, ConfigurationRepository, UserObj, UserCurrent, TimezoneService, $window) {
$scope.user_display_name = 'Not set yet';
$scope.getUser = function(username) {
// Code for getting user data
};
});
Despite setting the scope values before changing the $window.location
, the user_page.html loads without all fields being set. Any insights on why this might be happening?