【发布时间】:2014-02-01 17:41:34
【问题描述】:
我已经在 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 未定义.. 在 express 控制器中,我的 express 控制器代码如下
exports.login = function (req, res, next) { var
practiceName = String(req.body.pname); var 用户名 = 字符串(req.body.email); var userPass = String(req.body.password); };
------------- route.js app.post('/api/session', session.login); -------- html同上
在控制台我得到 practiceName 未定义
【问题讨论】:
-
你传递的是
practicename,而不是pname
标签: angularjs