I have encountered an issue with the login form code. Initially, I am able to reset the form fields and error messages successfully on the first attempt (both success and failure scenarios work). However, on the second try, I am unable to reset the form fields. Additionally, the login process fails to show any notifications for success or failure. This is due to the data being undefined at this point, leading to an error 415 (Unsupported Media Type) in the console. Strangely, if I remove the reset function, the login process works correctly. Can someone help me identify what I am doing wrong with the reset function?
Here is the part of the controller related to this issue:
App.controller('HomeCtrl', ['$scope', 'Users', '$window', '$location', '$rootScope',
function($scope, Users, $window, $location, $rootScope) {
var original = $scope.users;
$scope.users = {};
$scope.form = {};
$scope.reset = function() {
$scope.users = angular.copy(original);
$scope.form.loginForm.$setPristine();
};
} ]);