AngularJS 1.2.0升级:没有数据的模板/视图

时间:2013-11-12 12:44:35

标签: angularjs

从AngularJS 1.0.8升级到1.2.0后,我的模板(使用ng-repeat等)不再起作用了。这意味着在升级之后,使用AngularJS获取的数据不会显示在我的html页面中。知道发生了什么以及我必须改变什么?

但我可以看到(REST-)GET请求已成功处理,但页面中的数据未显示。

controller.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();
} ] );

services.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>

1 个答案:

答案 0 :(得分:0)

感谢您帮助兑现承诺。我现在正在使用的解决方案如下:

controllers.js

/* This line is replaced with ...then... */
//$scope.editransferlistdto = $scope.searchFactory( editransferlistdto );
$scope.searchFactory().then( function (editransferlistdto ){
    $scope.editransferlistdto = editransferlistdto;
});