Angular JS : Cannot read property 'substring' of undefined

3240 단어 angular.js
$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) {

        })

좋은 웹페이지 즐겨찾기