I'm currently working on implementing a login feature that directs a validated user to a personalized HTML view that greets them with their name.
The initial view is a login page. When the user clicks the "Log In" button, the ng-click
function is supposed to trigger my controller's $scope.login
, which validates the user, sets the $scope.needsLoggingIn
variable, and redirects to the second view (a welcome page displaying the value of $scope.needsLoggingIn
).
The issue I'm facing is that the second view (utilizing the same Angular Controller and Module) does not display the $scope.needsLoggingIn
variable when I attempt to set it within the $scope.login
function. It only shows the variable when I manually set the value in the controller, outside of any scope function, like this:
$scope.needsLoggingIn = "Betty";
Here is the $scope.login
function in my controller, which attempts to set the $scope.needsLoggingIn
and is recognized in the first view but not in the second:
$scope.login = function (username, password) {
$http({
method: 'GET',
url: ('/login/' + username + '/' + password)
}).then(function successCallback(response) {
if (JSON.stringify(response.data) === '[]')
{
$scope.needsPasswordMessage = true;
if ($scope.needsPasswordMessage)
$scope.needsPasswordMessage = false;
console.log("No match");
} else {
$scope.needsLoggingIn = username;
$scope.issuccessMessage = true;
if ($scope.isfailureMessage)
$scope.isfailureMessage = false;
$window.location.href = '../indextest.html';
return response;
}
}, function errorCallback(response) {
});
};
Any suggestions on how I can ensure that my $scope.needsLoggingIn
is recognized by both HTML views without hard-coding it into the controller? I would prefer for my $scope.login
function to set the variable value and be recognized by all views using this specific controller.