我已包含在默认登录的额外输入字段中。
<form class="form" name="form" ng-submit="login(form)" novalidate>
`<input type="text" name="pname" class="form-control" ng-model="user.pname" >`
<input type="text" name="email" class="form-control" ng-model="user.email">
<input type="password" name="password" class="form-control" ng-model="user.password">
<p class="help-block" ng-show="form.pname.$error.required && form.email.$error.required && form.password.$error.required && submitted"><button type="submit" lass="btn btn-info">Sign in</button></div>
但是pname没有被验证为空白,我也无法在我的控制器中获得pname的值
angular.module('ratefastApp')
.controller('LoginCtrl', function ($scope, Auth, $location) {
$scope.user = {};
$scope.errors = {};
$scope.login = function(form) {
$scope.submitted = true;
if(form.$valid) {
Auth.login({
email: $scope.user.email,
password: $scope.user.password,
practicename : $scope.user.pname
})
.then( function(err) {
$location.path('/');
})
.catch( function(err) {
err = err.data;
$scope.errors.other = err.message;
});
}
};
});
pname将不确定..在Express Controller中,我的Express Controller代码如下
exports.login = function(req,res,next){var
racticeName = string(req.body.pname);var用户名= 字符串(req.body.email);var userpass =字符串(req.body.password);};
------- HTML与上述 相同在控制台中,im练习不确定
尝试将required
放在您需要的字段上:
<input type="text" name="pname" class="form-control" ng-model="user.pname" required>
演示
您在Express Controller中获得pname
的undefined
的原因是因为您正在通过practicename
,而不是pname
:
Auth.login({
email: $scope.user.email,
password: $scope.user.password,
practicename : $scope.user.pname //you use practicename here.
})
尝试更换:
practiceName = String(req.body.pname);
with:
practiceName = String(req.body.practicename);