我已将额外输入字段包含在yeoman + express + angularjs完整堆栈应用程序中可用的默认login.html页面
<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未定义..在快速控制器中,我的快速控制器代码如下
exports.login = function(req,res,next){var
practiceName = String(req.body.pname); var userName = 串(req.body.email); var userPass = String(req.body.password); };
------------- route.js app.post('/ api / session',session.login); ------- html与上面相同
在控制台中获取practiceName undefined
答案 0 :(得分:0)
尝试将required
放在您需要的字段上:
<input type="text" name="pname" class="form-control" ng-model="user.pname" required>
您在快递控制器中获得undefined
pname
的原因是因为您传递的是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);
使用:
practiceName = String(req.body.practicename);