2016-05-09 3 views
0

ng-repeatのビューにデータを取得しようとしています。ビューがNGリピートを繰り返していませんMeteor.callからデータが表示されないAngling ng-repeat

<table id="datatable" class="table table-striped table-bordered"> 
    <thead> 
    <tr> 
     <th>Name</th> 
     <th>Position</th> 
     <th>Office</th> 
     <th>Age</th> 
     <th>Start date</th> 
     <th>Salary</th> 
    </tr> 
    </thead> 


    <tbody> 
    <tr ng-repeat="item in dashboardFaqs.faqs"> 
     <td>Tiger Nixon</td> 
     <td>System Architect</td> 
     <td>Edinburgh</td> 
     <td>61</td> 
     <td>2011/04/25</td> 
     <td>$320,800</td> 
    </tr> 
    </tbody> 
</table> 

はここで、コントローラ

class dashboardFaqsCtrl { 
    constructor($scope, $reactive) { 
    'ngInject'; 

    $reactive(this).attach($scope); 

    this.faqs = []; 

    Meteor.call('getFaqs', function (err, res) { 
     if (err) { 
     console.log(err); 
     } else { 
     console.log(res); 
     this.faqs = [res.data.faq]; 
     console.log(this.faqs); 
     } 
    }); 

    } 
} 

は、ここでの方法

import Future from 'fibers/future'; 

Meteor.methods({ 
    getFaqs: function() { 
    // Create our future instance. 
    var future = new Future(); 

    HTTP.get('http://example.com/faq', {}, function(error, response) { 
     if (error) { 
     future.return(error); 
     } else { 
     future.return(response); 
     } 
    }); 

    return future.wait(); 
    } 
}); 

ビューのです。

どのように角度ng-repeatを更新するか、このHTTPコールから返されたデータをサーバー側から表示できますか?

ありがとうございます! ANSWER

コメントと回答のおかげでそれを把握することができた、ここで私が変わっものです:

class dashboardFaqsCtrl { 
    constructor($scope, $reactive) { 
    'ngInject'; 

    $reactive(this).attach($scope); 

    this.faqs = []; 

    Meteor.call('getFaqs', function (err, res) { 
     if (err) { 
     console.log(err); 
     } else { 
     console.log(res); 
     this.faqs = res.data.faq; 
     $scope.dashboardFaqs.faqs = this.faqs; 
     console.log(this.faqs); 
     $scope.$apply(); 
     } 
    }); 

    } 
} 
+1

スコープを更新するにはangleを指定する必要があります。$ apply – aw04

+0

@johhanをチェックしてください。controllerAsの構文を使用しているので、$ scopeは必要ありません。 controllerAs構文を使用する場合は、$ scopeの代わりに* this *を使用するだけです。 turorialのこのページをチェックしてください:http://www.angular-meteor.com/tutorials/socially/angular1/3-way-data-bindingもちろん、aw04のように、angleを指定してバインディングを更新するには、$ applyが必要です。また、あなたはあなたのng-repeatでそれを使用しているので、あなたは「this」に* dashboardFaqs *が必要だと思います。 –

答えて

1

あなたは$スコープにデータを渡す必要が

class dashboardFaqsCtrl { 
    constructor($scope, $reactive) { 
    'ngInject'; 

    $reactive(this).attach($scope); 

    this.faqs = []; 

    Meteor.call('getFaqs', function (err, res) { 
     if (err) { 
     console.log(err); 
     } else { 
     console.log(res); 

     this.faqs = [res.data.faq]; 
     $scope.dashboardFaqs = this.faqs; 
     console.log(this.faqs); 
     } 
    }); 

    } 
} 

試してみてください!

関連する問題