I am currently in the process of transitioning from Knockout to Angular. However, I have encountered some challenges that I haven't been able to overcome yet.
Within the login function of my website, I make an ajax call to retrieve user information which is then set in the controller.
This is how it looks:
$scope.login = function () {
var data = {
userName: $('#txtLoginName').val(),
password: $('#txtLoginPassword').val(),
};
console.info(data);
postJSON("/StrengthTracker/User/Login", data, function (result) {
if (result.result == "ok") {
$('#loginDialog').modal('hide');
//setting controller variables <------------
$scope.isLoggedIn = true;
$scope.userId = result.userId;
$scope.userName = result.userName;
$scope.publicId = result.publicId;
$scope.gender = result.gender;
$scope.unitName = result.unit;
console.info(result);
notify("Welcome " + $scope.userName);
}
if (result.result == "fail") {
notifyFail("Login failed");
}
});
}
Although the correct data is returned and the notify(..) call displays "Welcome Roger" for instance, it seems like Angular doesn't recognize that the variables have been updated.
Only when I trigger the login function again does Angular acknowledge the changes and realize that the user is logged in.
Any thoughts or suggestions?