Angular ng-repeat 不显示来自 Meteor.call 的数据
Angular ng-repeat not showing data from Meteor.call
我正在尝试将数据获取到 ng-repeat 中的视图。
这是控制器
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();
}
});
观点:
<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>0,800</td>
</tr>
</tbody>
</table>
视图不重复 ng-repeat。
如何使 angulars ng-repeat 更新或显示服务器端从该 HTTP 调用返回的数据?
谢谢!
回答
多亏了评论和答案才弄明白,这是我改变的地方:
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();
}
});
}
}
您必须在 $scope
中传递数据
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);
}
});
}
}
试一试!!!
我正在尝试将数据获取到 ng-repeat 中的视图。
这是控制器
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();
}
});
观点:
<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>0,800</td>
</tr>
</tbody>
</table>
视图不重复 ng-repeat。
如何使 angulars ng-repeat 更新或显示服务器端从该 HTTP 调用返回的数据?
谢谢!
回答
多亏了评论和答案才弄明白,这是我改变的地方:
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();
}
});
}
}
您必须在 $scope
中传递数据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);
}
});
}
}
试一试!!!