Angular JS : Cannot read property 'substring' of undefined

$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) {})


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部