从 AngularJS 1.0.8 升级到 1.2.0 后,我的模板(使用 ng-repeat 等)不再起作用。这意味着升级后使用 AngularJS 获取的数据不会显示在我的 html 页面中。知道发生了什么以及我必须改变什么吗?
但我可以看到 (REST-)GET-request 已成功处理,但页面中的数据未显示。
控制器.js:...
app.config( [ '$routeProvider', function( $routeProvider ) {
$routeProvider.when( '/editransferlist', {
controller : 'EditransferListCtrl',
resolve : {
editransferlistdto : function( EditransferListLoader ) {
//return EditransferListLoader();
return null;
}
},
templateUrl : 'app/view/editransfer-list.html'
...
app.controller( 'EditransferListCtrl', [ '$scope', 'editransferlistdto', 'EditransferListLoader', '$q', 'EditransferService', '$location',
'$routeParams', '$route',
function( $scope, editransferlistdto, EditransferListLoader, $q, EditransferService, $location, $routeParams, $route ) {
$scope.editransferlistdto = editransferlistdto;
$scope.searchfilter = {
datenbestand : "",
nachname : ""
};
$scope.pagination = {
page : 1,
maxresults : 10
};
$scope.searchFactory = EditransferListLoader;
$scope.search = function( selectedpage ) {
$scope.pagination.page = selectedpage || this.page || 1;
$routeParams.searchfilter = $scope.searchfilter;
$routeParams.pagination = $scope.pagination;
$route.current.params.searchfilter = $scope.searchfilter;
$route.current.params.pagination = $scope.pagination;
$scope.editransferlistdto = $scope.searchFactory();
};
$scope.search();
} ] );
服务.js
var services = angular.module( 'avportal.services', [ 'ngResource' ] );
services.factory( 'EditransferService', [ '$resource', '$routeParams', function find( $resource, $routeParams ) {
return $resource( '/av-portal/rest/editransfer/:id',
{
id : '@id' || null,
isArray : false
} );
} ] );
services.factory( 'EditransferListLoader', [ 'EditransferService', '$q', '$route', '$location', '$routeParams',
function( EditransferService, $q, $route, $location, $routeParams ) {
var find = function find() {
var delay = $q.defer();
EditransferService.get( {
page : $route.current.params.pagination.page,
maxresults : $route.current.params.pagination.maxresults,
datenbestand : $route.current.params.searchfilter.datenbestand,
nachname : $route.current.params.searchfilter.nachname
}, function( editransferlistdto ) {
delay.resolve( editransferlistdto );
}, function() {
delay.reject( 'Unable to fetch' );
} );
return delay.promise;
};
return find;
} ] );
html:
<tr ng-repeat="maindto in editransferlistdto.aaData">
<td>{{maindto.id}}</td>
</tr>