与父母不同的服务解决的子视图/路由

时间:2015-03-30 17:59:29

标签: angularjs ionic-framework ionic

我在从父视图/路由解析来自不同服务的GET时遇到加载子视图/路由的问题。

在父视图中,每个离子项链接到/#/tab/categories/{{ category.listing_category_id }} 当点击URL填充(对于闪存)具有正确类别ID的URL时,子服务成功接收类别ID,运行后续GET请求&将数据作为承诺返回......所有数据都按预期工作。问题是子视图/路由永远不会加载。非常感谢所有帮助/指导。

angular.module('rainbowPages.tab.categories', [])

.config(function($stateProvider, $urlRouterProvider) {
    // UI Router
    $stateProvider.state('tab.categories', {
        url: '/categories',
        views: {
            'tab-categories': {
                templateUrl: 'views/tab-categories/tab-categories.html',
                controller: 'CategoriesCtrl'
            }
        }
    });

    // otherwise
    $urlRouterProvider.otherwise('/tab/categories');
})

.factory('CategoriesService', function($resource) {
    var remoteCategoriesURL = 'http://104.167.104.163:7000/api/v1/categories',

        categoriesService   = $resource(remoteCategoriesURL, {}, {
            getAll: {
                method: 'GET',
                isArray: true
            }
        });

  return categoriesService;
})

.controller('CategoriesCtrl', function($scope, CategoriesService) {
    $scope.categories = CategoriesService.getAll();
});

儿童

angular.module('rainbowPages.tab.categories.detail', [])

.config(function($stateProvider, $urlRouterProvider) {
    // UI Router
    $stateProvider.state('tab.category-detail', {
        url: '/categories/:listing_category_id',

        views: {
            'tab-categories': {
                templateUrl: 'views/category-detail/category-detail.html',
                controller: 'categoryDetailCtrl'
            }
        },

        resolve: {
            listings: function($stateParams, CategoryDetailService) {
                // bind data to listing
                return CategoryDetailService($stateParams.listing_category_id);
            }
        }
    });
})


.factory('CategoryDetailService', function($resource) {
    var remoteCategoryURL     = 'http://104.167.104.163:7000/api/v1/category/:categoryID',

        categoryDetailService = $resource(remoteCategoryURL, {categoryID:'@listing_category_id'}, {
            get: {
                method: 'GET',
                isArray: true
            }
        }),

        getListingsInCategory = function getListingsInCategory(categoryID) {
            listingsInCategory = categoryDetailService.get({categoryID:categoryID}, function(promise) {
                if(promise.$resolved = true) {
                    console.log(promise); // how I know the promise has the correct data
                    return promise;
                }
            });
        };

    return getListingsInCategory;
})


.controller('categoryDetailCtrl', function($scope, listings){
    console.log('listings are : ' + listings);
    $scope.listings = listings;
});

0 个答案:

没有答案