Using a factory inside another factory AngularJS

后端 未结 2 839
萌比男神i
萌比男神i 2021-02-12 18:58

I have a module...

angular.module(\'myModule\', []);

And then a factory

angular.module(\'myModule\')
.factory(\'factory1\', [
          


        
2条回答
  •  终归单人心
    2021-02-12 19:55

    This is what i did and worked fine. Call SessionPresenters from Session

    angular.module('tryme3App')
        .factory('Session', function ($resource, DateUtils, SessionPresenters) {
            return $resource('api/sessions/:id', {}, {
                'query': { method: 'GET', isArray: true},
                'get': {
                    method: 'GET',
                    transformResponse: function (data) {
                        data = angular.fromJson(data);
    
                        var result = SessionPresenters.get({id: data.id})
                        data.presenters = result; 
                        return data;
                    }
                },
                'update': { method:'PUT' }
            });
        }).factory('SessionPresenters', function ($resource, DateUtils) {
            return $resource('api/session.Presenters/:id', {}, {
                'query': { method: 'GET', isArray: true},
                'get': {
                    method: 'GET', isArray: true
                },
                'update': { method:'PUT' }
            });
        });
    

提交回复
热议问题