Home >Web Front-end >JS Tutorial >Example code sharing of how to use Angularjs to change password
This article mainly introduces the example code of Angularjs. It is very good and has reference value. Friends in need can refer to it
Modify password logical thinking
First enter the old password to determine whether the old password is correct (backend judgment)
Secondly enter the new password and determine the new password format (can be Add)
Finally determine whether the new password and confirmed password input are consistent
html part
<form class="form-horizontal" role="form"> <p class="form-group"> <label class="col-sm-2 control-label"><i class="importance">*</i>当前密码</label> <p class="col-sm-6"> <input type="text" class="form-control" ng-model="user.password"> </p> </p> <p class="form-group"> <label class="col-sm-2 control-label"><i class="importance">*</i>新密码</label> <p class="col-sm-6"> <input type="text" class="form-control" ng-model="user.newPassword" ng-minlength="8" ng-maxlength="16" required> </p> </p> <p class="form-group"> <label class="col-sm-2 control-label"><i class="importance">*</i>确认新密码</label> <p class="col-sm-6"> <input type="text" class="form-control" ng-model="password_again"> </p> </p> <p class="form-group"> <p class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-default x_submit" ng-click="changePassword()">保存设置</button> </p> </p> </form>
AngularJS part
.controller('userpswdCtrl', function($scope,Account,SweetAlert,$state,$localStorage){ $scope.user = {}; //信息全部存在user里面 $scope.changePassword = function(){ if($scope.password_again === $scope.user.newPassword){ //如果两次密码输入一致 $scope.user.accountId = $localStorage.accountId; //获取用户id Account.modifyPassword($scope.user,function(data){ //修改密码 console.log(data); SweetAlert.swal({ title:'', text: "修改成功", type: "success", showCancelButton: false, confirmButtonColor: "#DD6B55", confirmButtonText: "是", cancelButtonText: "否", closeOnConfirm: true, closeOnCancel: true }) },function(){ }) } } })
The above is the detailed content of Example code sharing of how to use Angularjs to change password. For more information, please follow other related articles on the PHP Chinese website!