2016-08-03 2 views
0

내 앱에 ngInfiniteScroll - Loading Remote Data을 구현하려하고 있습니다.AngularJS가있는 NodeJS 서버에서 JSONP을 반환

데모가 제대로 작동합니다. & 성공적으로 Reddit API를 받고 있지만 작동하지 않습니다.

200 서버 응답 &은 내 데이터를 dev 도구에서 볼 수 있습니다. 이 답변들은 약간의 도움이되었습니다. 1 & 2 그러나 나는 아직도 무엇을해야할지 잘 모르고 있습니다.


EDIT (각 공장의 편집 참조)

이 콜백 지금 노력하고 있습니다

$http을하지만 지금 Cannot read property 'length' of undefined


을 얻고 성공에가는 각도 공장 :

Reddit.prototype.nextPage = function() { 
    if (this.busy) return; 
    this.busy = true; 

    // Edit - I changed this var from 
    // var url = config_api.API_ENDPOINT_LOCAL + "list?after=" + this.after + "?alt=json-in-script&jsonp=JSON_CALLBACK"; 
    // to 
    var url = config_api.API_ENDPOINT_LOCAL + "list?after=" + this.after + "?alt=json-in-script&callback=JSON_CALLBACK"; 

    $http.jsonp(url) 
    .success(function(data) { 
     console.log(data); 
     var items = data.children; 
     for (var i = 0; i < items.length; i++) { 
     this.items.push(items[i].data); 
     } 
     this.after = "t3_" + this.items[this.items.length - 1].id; 
     this.busy = false; 
    }.bind(this)); 
    console.log('Reddit.prototype'); 
}; 

NodeJS 경로 :

app.get('/list', function (req, res) { 

    Found.find(function (err, post) { 
    if (err) { 
     res.send(err); 
    } 
    res.jsonp(post); 
    }); 

}); 
+0

항목은 정의되어 있어야합니다. 다른 곳에서는'.length'가 보이지 않습니까? console.log가있는 곳에서'debugger' 라인을 삭제 해보면 실행중인 변수의 값을 검사 할 수 있습니다. 아, 나는 그것을 볼 것 같아요 ... 답변을 게시 할 것입니다 .... 아니, 대답에 대해 다시 가져 가라.하지만 당신이 할 때 항목이 명확하게 정의되지 않았습니다. 그렇지 않으면 그 오류가 없을 것입니다. – shaunhusain

+0

@shaunhusain, 그래서 내 데이터가 서버에서 반환 된 모든 값과 함께'data = [Object, Object]'로 돌아오고있다. – Mark

+0

대화식 디버거 (F12 -> Sources 패널을 열거 나 F12를 열어서 디버거 ;'문에서) 당신은 파수꾼을 추가하거나 그곳의 지역 변수를 체크하여 어떤 데이터인지, 어떤 데이터가 있는지를 확인하고 항목이 배열인지 확인하고 F10 또는 그 작은 코드를 따라 가면됩니다 화살표가 디버그 도구에서 원 위로 이동합니다. – shaunhusain

답변

2
Reddit.prototype.nextPage = function() { 
    if (this.busy) return; 
    this.busy = true; 

    // Edit - I changed this var from 
    // var url = config_api.API_ENDPOINT_LOCAL + "list?after=" + this.after + "?alt=json-in-script&jsonp=JSON_CALLBACK"; 
    // to 
    var url = config_api.API_ENDPOINT_LOCAL + "list?after=" + this.after + "?alt=json-in-script&callback=JSON_CALLBACK"; 

    $http.jsonp(url) 
    .success(function(data) { 
     console.log(data); 
     var items = data; 
     for (var i = 0; i < items.length; i++) { 
     this.items.push(items[i]); 
     } 
     this.after = "t3_" + this.items[this.items.length - 1].id; 
     this.busy = false; 
    }.bind(this)); 
    console.log('Reddit.prototype'); 
}; 

는 그것을 해결해야!

+0

100 % 효과! 고맙습니다! – Mark