Javascript 如何使用ngResource在ngTable中填充数据,但在不点击API调用的情况下进行搜索和排序?
我有一个ngTable,当控制器使用ngResource查询API调用以获取响应数组时,我想在其中填充数据 服务(在两种情况下使用相同) 案例1:Javascript 如何使用ngResource在ngTable中填充数据,但在不点击API调用的情况下进行搜索和排序?,javascript,angularjs,ngtable,ngresource,Javascript,Angularjs,Ngtable,Ngresource,我有一个ngTable,当控制器使用ngResource查询API调用以获取响应数组时,我想在其中填充数据 服务(在两种情况下使用相同) 案例1: angular.module('temp').component('tempB', { templateUrl: 'template/B/tempB.template.html', controller: ['TemplateBlockFactory', 'NgTableParams'], function Temp
angular.module('temp').component('tempB', {
templateUrl: 'template/B/tempB.template.html',
controller: ['TemplateBlockFactory', 'NgTableParams'],
function TemplateBCtrlr(TemplateBlockFactory, NgTableParams) {
var self = this;
var tableData = [];
tableData = TemplateBlockFactory.query();
self.tableParams = new NgTableParams({}, {dataset: tableData});
}
})
angular.module('temp').component('tempB', {
templateUrl: 'template/B/tempB.template.html',
controller: ['TemplateBlockFactory', 'NgTableParams'],
function TemplateBCtrlr(TemplateBlockFactory, NgTableParams) {
var self = this;
self.tableParams = new NgTableParams({}, {
getData: function (params) {
return TemplateBlockFactory.query();
}
});
}
})
案例2:
angular.module('temp').component('tempB', {
templateUrl: 'template/B/tempB.template.html',
controller: ['TemplateBlockFactory', 'NgTableParams'],
function TemplateBCtrlr(TemplateBlockFactory, NgTableParams) {
var self = this;
var tableData = [];
tableData = TemplateBlockFactory.query();
self.tableParams = new NgTableParams({}, {dataset: tableData});
}
})
angular.module('temp').component('tempB', {
templateUrl: 'template/B/tempB.template.html',
controller: ['TemplateBlockFactory', 'NgTableParams'],
function TemplateBCtrlr(TemplateBlockFactory, NgTableParams) {
var self = this;
self.tableParams = new NgTableParams({}, {
getData: function (params) {
return TemplateBlockFactory.query();
}
});
}
})
模板
<div class="box-body">
<table ng-table="$ctrl.tableParams" class="table table-bordered table-striped" show-filter="true">
<tr ng-repeat="block in $data">
<td data-title="'#'" filter="{ id: 'number'}" sortable="'id'">{{ $index+1 }}</td>
<td data-title="'Name'" filter="{ name: 'text'}" sortable="'name'">{{ block.name }}</td>
<td data-title="'Width'" filter="{ width: 'number'}" sortable="'width'">{{ block.width }}</td>
<td data-title="'Height'" filter="{ height: 'number'}" sortable="'height'">{{ block.height }}</td>
</tr>
</table>
</div>