错误:undefined不是对象(正在评估'$scope.inputcode.password')
Error: undefined is not an object (evaluating '$scope.inputcode.password')
HTML:
<form ng-submit="mylogin()">
<div class="list">
<label class="item item-input">
<span class="input-label">Username</span>
<input type="text" ng-model="inputcode.username">
</label>
<label class="item item-input">
<span class="input-label">Password</span>
<input type="password" ng-model="inputcode.password">
</label>
<label class="item">
<button class="button button-block" type="submit">Log in</button>
</label>
</div>
</form>
<br>
{{inputcode.password}}<---testing for correct syntax and it works fine here
控制器:
$scope.inputcode;
$scope.discountcodes=['phillyd','kevin','john'];
$scope.mylogin = function() {
for (var i=0; i<$scope.discountcodes.length; i++) {
if($scope.inputcode.password==$scope.discountcodes[i]){
console.log($scope.discountcodes[i]);
}
else{
console.log("You failed to crack the code young jedi");
}
}
}
这是我不断得到的错误:
错误:undefined不是对象(评估"$scope.inputcode.password")
我已经测试了$scope.inputcode.password是否有效,并通过在我的html页面上显示{{inputcode.paassword}}来保存信息。
我不明白到底是什么错误?
提前感谢:)
您已经声明了$scope.inputcode
,但不是作为对象声明的——因为它当前存在,它只是undefined
。您需要将其初始化为一个对象,如下所示:
$scope.inputcode = {};
这将允许您将其作为对象进行评估。
相关文章:
- AngularJS:ng之后,重复$scope值未按预期更新
- $ionicplatform内的$scope不;不起作用
- 使用$scope方法时的ControllerAs语法
- 如何将ngrepeat下的ngmodel绑定到$scope
- 另一个if(!$scope.$$phase)$scope$apply()szenario-需要帮助才能通关
- 使用AngularJS Directive WHITOUT$scope创建一个动态html元素
- $scope变量被视为字符串AngularJs
- ng在更新$scope后重复不更新信息
- 正在获取Angular以检测$scope中的更改
- 如何惯用地手动销毁scope&在AngularJS中重新创建
- Understanding Javascript scope with "var that = this&qu
- AngularJS,angular.element($0).scope()揭示了每个控制器的函数
- Ng出口无法访问父$scope
- ng选项-用vm替换$scope
- $scope变量,ng隐藏/显示
- 强制 $scope.$watch 只开火一次
- Ionic:AngularJS变量未使用$scope更新DOM
- Angular$scope在模式窗口内不起作用
- 在将绑定应用于控制器之后,是否会发出Angular$scope事件
- 错误:undefined不是对象(正在评估'$scope.inputcode.password')