Angular JS : Cannot read property 'substring' of undefined,angularsubstring
分享于 点击 33699 次 点评:261
Angular JS : Cannot read property 'substring' of undefined,angularsubstring
$http({
method : 'GET',
url : urls,
// 数据类型
dataType : "json",
// 要传递的数据
data : "",
}).then(function successCallback(response) {
$scope.credit = response.data;
var ceditScope=$scope.credit.credit_score;
$scope.updateTime="更新于:"+response.data.updateTime.substring(0,10);
$scope.change(ceditScope);
$('.thirdline').text($scope.updateTime);
}, function errorCallback(response) {
})
报此错误原因在于对字符串做substring时,没有判断其是否为空。
按如下方式修改后即可解决:
$http({
method : 'GET',
url : urls,
// 数据类型
dataType : "json",
// 要传递的数据
data : "",
}).then(function successCallback(response) {
$scope.credit = response.data;
var ceditScope=$scope.credit.credit_score;
if(!!response.data.updateTime){
$scope.updateTime="更新于:"+response.data.updateTime.substring(0,10);
$('.thirdline').text($scope.updateTime);
}else{
$('.thirdline').text("");
}
$scope.change(ceditScope);
}, function errorCallback(response) {
})
相关文章
- 暂无相关文章
用户点评