ngResource - 不在浏览器中显示数据
ngResource - doesn't show data in browser
我对 ngResource 有疑问。
这是我的 .factory
app.factory('sveKlupeServiceFactory', ['$resource',
function($resource){
return $resource('myURL/to/json', {},{
// { method: 'getKlupe', q: '*' },
query: { method: 'GET', params:{klupaId:'klupe'}, isArray:true}
});
这是我的控制器
app.controller('klupeController', ['$scope', 'sveKlupeServiceFactory', function ($scope,sveKlupeServiceFactory){
$scope.klupe = sveKlupeServiceFactory.query();
}]);
在 html 我有这个
<tr ng-repeat="klupa in klupe">
<td>{{klupa.serial_number}}</td>
<td>{{klupa.location_id}}</td>
<td>{{klupa.type}}</td>
<td>{{klupa.last_report_dt}}</td></tr>
问题:
在我的浏览器中,我有 table,但有空行。没有任何错误。
在我的应用程序中我有
var app = angular.module('App', [
'ngRoute',
'ngResource']);
有人可以帮我提点建议吗?
谢谢。
如果您想要完整的 table 数据,那么在调用工厂方法时,factory.Make 控制器中的以下更改无需将 id 作为参数传递。
使用 console.log()
检查响应
sveKlupeServiceFactory.query(function(res){
console.log(res);
$scope.klupe = res;
});
您应该使用承诺来获得响应。
$scope.klupe = sveKlupeServiceFactory.query();
$scope.klupe.$promise.then( function(result) { $scope.klupe = result });
我对 ngResource 有疑问。 这是我的 .factory
app.factory('sveKlupeServiceFactory', ['$resource',
function($resource){
return $resource('myURL/to/json', {},{
// { method: 'getKlupe', q: '*' },
query: { method: 'GET', params:{klupaId:'klupe'}, isArray:true}
});
这是我的控制器
app.controller('klupeController', ['$scope', 'sveKlupeServiceFactory', function ($scope,sveKlupeServiceFactory){
$scope.klupe = sveKlupeServiceFactory.query();
}]);
在 html 我有这个
<tr ng-repeat="klupa in klupe">
<td>{{klupa.serial_number}}</td>
<td>{{klupa.location_id}}</td>
<td>{{klupa.type}}</td>
<td>{{klupa.last_report_dt}}</td></tr>
问题: 在我的浏览器中,我有 table,但有空行。没有任何错误。
在我的应用程序中我有
var app = angular.module('App', [
'ngRoute',
'ngResource']);
有人可以帮我提点建议吗?
谢谢。
如果您想要完整的 table 数据,那么在调用工厂方法时,factory.Make 控制器中的以下更改无需将 id 作为参数传递。 使用 console.log()
检查响应sveKlupeServiceFactory.query(function(res){
console.log(res);
$scope.klupe = res;
});
您应该使用承诺来获得响应。
$scope.klupe = sveKlupeServiceFactory.query();
$scope.klupe.$promise.then( function(result) { $scope.klupe = result });