angularjs - Issue with angular animation and undefined javascript values -
i trying angular animation triggered upon unsuccessful login (either when server sends 4xx (e.g. 403) or when no credentials provided).
here controller:
.controller('signinctrl', ['$scope', '$rootscope', '$cookies', '$state', '$animate', 'signinservice', function ($scope, $rootscope, $cookies, $state, $animate, signinservice) { $scope.signin = function () { $scope.shake = false; if ($scope.credentials) { signinservice.signin($scope.credentials, function (status, memberrole) { $scope.shake = false; //todo: necessary check status? if (status === 200) { ... } }, function () { $scope.shake = true; }); } else { //todo: shakes/works once! $scope.shake = true; } } }]);
the form:
<form class="form-signin" ng-class="{shake: shake}" name="signinform" ng-submit="signin()" novalidate> <h2 class="form-signin-heading signin-title">{{'signin' | translate}}</h2> <input type="email" ng-required name="username" ng-model="credentials.username" class="form-control" placeholder="{{'signin_form_email'| translate}}"/> <input type="password" ng-required name="password" ng-model="credentials.password" class="form-control" placeholder="{{'signin_form_password'| translate}}"/> <button class="btn btn-lg btn-primary btn-block" type="submit">{{'signin' | translate}}</button> <div class="forgot-password"> <a ui-sref="sendpasswordresetinformation">{{'signin_form_forgotten_password' | translate}}</a> </div> </form>
however, if form has no credentials in inputs (nothing in not empty string) form shakes once.
can please help?
edit 1:
.factory('signinservice', ['$http', function ($http) { return { signin: function (credentials, successcallback, errorcallback) { var transform = function (data) { return $.param(data); } return $http.post('/api/signin', credentials, { headers: {'content-type': 'application/x-www-form-urlencoded; charset=utf-8'}, transformrequest: transform }).success(function (data, status, headers) { if (status === 200) { successcallback(status, headers('member_role')); } else { console.log('auth error'); successcallback('error'); } }).error(function(data, status, headers) { console.log("error!", data, status, headers); errorcallback(); }); } } }]);
changing controller :
... $scope.signin = function () { $scope.shake = false; $scope.$apply();//added! ...
fixed issue. floribon...
Comments
Post a Comment