我遇到了“无法读取未定义的属性'indexOf'的问题”。以下是源代码。感谢您的帮助。
$http.get("js/project/data.json").then(function(response) {
//$scope.case = response.data.caseno;
$scope.case = response.data.caseno.map(function(elem) {
return elem.toLowerCase();
});
});
console.log($scope.project.ProjectCaseNo.toLowerCase());
if($scope.case.indexOf($scope.project.ProjectCaseNo.toLowerCase()) != -1 ){
$scope.glyphicon = 'glyphicon-ok green';
$scope.CaseMessage = 'Valid Case No.';
}else{
$scope.glyphicon = 'glyphicon-remove red';
$scope.CaseMessage = 'Invalid Case No.';
};
};
答案 0 :(得分:2)
改变它是这样的:
$scope.VerifyCaseNo = function(){
$http.get("js/project/data.json").then(function(response) {
//$scope.case = response.data.caseno;
$scope.case = response.data.caseno.map(function(elem) {
return elem.toLowerCase();
});
console.log($scope.project.ProjectCaseNo.toLowerCase());
if($scope.case.indexOf($scope.project.ProjectCaseNo.toLowerCase()) != -1 ){
$scope.glyphicon = 'glyphicon-ok green';
$scope.CaseMessage = 'Valid Case No.';
}else{
$scope.glyphicon = 'glyphicon-remove red';
$scope.CaseMessage = 'Invalid Case No.';
};
});
};
在$scope.case
操作完成之前,您的$http.get()
将被取消定义。所以你得到了未定义错误的无法读取属性'indexOf'!
答案 1 :(得分:0)
您可以使用String(yourValue).indexOf('')