【发布时间】:2017-05-14 14:49:17
【问题描述】:
我检查了类似的问题,但没有一个适用于这种情况。
我有一个 Angular 应用程序,我正在尝试手动验证它,但我遇到了问题。
为简单起见,我只包括电子邮件字段,表单字段已在另一个函数中验证,并且该函数将 $scope.regform.email.valid 变量设置为 true 或 False。
当你故意在字段中输入不正确的信息时,这很好用,但如果没有输入,并且按下了注册按钮,我想做一个 isDefined 检查,这似乎不起作用。
//this is inside the function that runs is the register button is pressed.
//in this test case nothing has been entered in the email field when the register button is pressed.
email = angular.isDefined($scope.regform.email.valid);
console.log(email);
isDefined 函数用于检查变量是否已定义,但如果未定义,则会发生以下错误,而不是 'email' 评估为 false。
TypeError: $scope.regform.email is undefined
Stack trace:
studyseshController/$scope.checkValid@http://localhost:8000/bundles/framework/js/app.js:17:13
anonymous/fn@http://localhost:8000/bundles/framework/js/angular.min.js line 239 > Function:2:147
bd[b]</<.compile/</</e@http://localhost:8000/bundles/framework/js/angular.min.js:284:195
Mf/this.$get</m.prototype.$eval@http://localhost:8000/bundles/framework/js/angular.min.js:148:351
Mf/this.$get</m.prototype.$apply@http://localhost:8000/bundles/framework/js/angular.min.js:149:55
bd[b]</<.compile/</<@http://localhost:8000/bundles/framework/js/angular.min.js:284:245
r.event.dispatch@https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js:3:10264
r.event.add/q.handle@https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js:3:8326
angular.min.js:123:218
【问题讨论】:
-
也许你的答案在这里:stackoverflow.com/questions/27818331/…
标签: javascript jquery angularjs