【发布时间】:2017-03-10 15:16:49
【问题描述】:
在 Angular 模块“md-data-table”的自述文件中,它说“假设我们有一个 $nutrition 服务”。我尝试添加一个服务(makerService),并返回数据。但我看不到屏幕上显示的数据。我尝试了不同的 JSON 格式,但出现错误:
$makerService.makers.get is not a function
这是我的 Javascript 代码:
(function() {
'use strict';
angular.module('BowbleCRM', [
'ngMaterial',
'md.data.table'
])
.service('$makerService', function () {
var makers = {
"makers" : [
{"full_name": "Jan", "email": "jan@test.nl"},
{"full_name": "Pieter", "email": "pieter@test.nl"}
]
};
return makers;
})
.controller('BowbleCRMController', ['$makerService', '$scope', BowbleCRMController]);
function BowbleCRMController($makerService, $scope) {
'use strict';
$scope.currentNav = 'importeren';
$scope.selected = [];
$scope.query = {
order: 'full_name',
limit: 5,
page: 1
};
function success(makers) {
console.log(makers);
$scope.makers = makers;
}
$scope.getMakers = function () {
$scope.promise = $makerService.makers.get($scope.query, success).$promise;
};
}
})();
这是我的 HTML 的一部分。
<md-toolbar class="md-table-toolbar md-default">
<div class="md-toolbar-tools">
<span>Alle makers</span>
</div>
</md-toolbar>
<!-- exact table from live demo -->
<md-table-container>
<table md-table md-row-select multiple ng-model="selected" md-progress="promise">
<thead md-head md-order="query.order" md-on-reorder="getMakers">
<tr md-row>
<th md-column><span>Volledige naam</span></th>
<th md-column><span>E-Mail adres</span></th>
</tr>
</thead>
<tbody md-body>
<tr md-row md-select="maker" md-select-id="full_name" md-auto-select ng-repeat="maker in makers.data">
<td md-cell>{{maker.full_name}}</td>
<td md-cell>{{maker.email}}</td>
</tr>
</tbody>
</table>
</md-table-container>
<md-table-pagination md-limit="query.limit" md-limit-options="[5, 10, 15]" md-page="query.page" md-total="{{makers.length}}" md-on-paginate="getMakers" md-page-select></md-table-pagination>
如何提供正确的服务,并使用 Angular 模块“md-data-table”显示数据?
【问题讨论】:
-
$makers 服务中的“GET”功能在哪里?目前,$makerService.makers 对象没有“GET”功能,只有 full_name 和 email。
标签: javascript angularjs material-design