Javascript 错误:undefined不是对象(正在计算';$scope.inputcode.password';)
HTML:Javascript 错误:undefined不是对象(正在计算';$scope.inputcode.password';),javascript,html,angularjs,ionic-framework,Javascript,Html,Angularjs,Ionic Framework,HTML: 用户名 密码 登录 {{inputcode.password}您已经声明了$scope.inputcode,但不是作为一个对象-因为它当前存在,它只是未定义的。您需要将其初始化为对象,如下所示: $scope.inputcode; $scope.discountcodes=['phillyd','kevin','john']; $scope.mylogin = function() { for (var i=0; i<$scope.discountcodes.l
用户名
密码
登录
{{inputcode.password}您已经声明了$scope.inputcode
,但不是作为一个对象-因为它当前存在,它只是未定义的。您需要将其初始化为对象,如下所示:
$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");
}
}
}
这将允许您将其作为对象进行评估
$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");
}
}
}
$scope.inputcode = {};