2014-09-10 3 views
1

필터를 사용하여 리피터에서 ID를 추출하고 있습니다. 그것은 모두 잘 작동하지만 콘솔에서 나는 다음과 같은 오류가 점점 오전 :

https://docs.angularjs.org/error/$interpolate/interr?p0=%7B%7BspecsList%20%7C%20splitIds%7D%7D&p1=TypeError:%20Cannot%20read%20property%20%27map%27%20of%20undefined 

내가 specsList정적 값으로 $http.get를 교체 할 경우, 오류가 없습니다. 좋은 방법으로 그 문제를 해결하는 방법에 대한 아이디어가 있습니까?

JS :

app.controller('SpecsController', function ($scope, $http) { 
    $scope.$on('$viewContentLoaded', function(event) { 
     $http.get('getSpecs.aspx') 
      .then(function(result) { 
      $scope.specsList = result.data.specs; 
      }) 
      .catch(function(err) { 
      console.log(err); 
      }); 
    }); 

    $scope.sortableOptions = { 
     handle: "> .position", 
     helper: function (e, ui) { 
       var originals = ui.children(); 
       var clonedHelper = ui.clone(); 
       clonedHelper.children().each(function(index) { 
       //$(this).width($(this).width()); 
       $(this).width(originals.eq(index).outerWidth()); 
       $(this).addClass("dragging"); 
       $(this).parent().addClass("dragging_tr"); 
       }); 
       return clonedHelper; 
     }, 
     update: function(e, ui) { 
      //console.log("update"); 
     }, 
     stop: function(e, ui) { 
      //Save sortorder 
     } 
    }; 
}); 

app.filter('splitIds', function() { 
    return function(ArrayWithIds) { 
     return ArrayWithIds.map(function(item){return item.id;}).join(); 
    }; 
}); 

HTML : 약속이 반환되고

<input type="text" value="{{specsList | splitIds}}" /> 

답변

0

확인에 $http.get('getSpecs.aspx')을 변경해야

app.filter('splitIds', function() { 
    return function(ArrayWithIds) {   
     return (angular.isUndefined(ArrayWithIds) || !angular.isArray(ArrayWithIds))? 
       "": 
       ArrayWithIds.map(function(item){return item.id;}).join(); 
    }; 
}); 

필터 splitIds이 처음으로 $scope.specsList이라고 불리는 것은 아직 존재하지 않습니다.

+0

감사합니다. 정말 감사합니다! – peta

0

때문에, 당신이 당신의 문제를 해결해야 return $http.get('getSpecs.aspx')

+0

'$ http.get()'호출은 이벤트 콜백에 있으므로 어떻게 반환 될 수 있습니까? 설명 해주십시오. – MiTa

+0

반환 $ http.get ('getSpecs.aspx')와 함께 오류가 계속 발생합니다. – peta

관련 문제