Sorry, I pasted the wrong controller that applies to this question, try:

  function ClassroomContentDirective(ClassroomContent, OtherService) {

    function link($scope, $elem, $attrs, $classCntrl) {

      OtherService.pagedView = $classCntrl.service = new ClassroomContent({
        path: $attrs.get,
        isInfiniteScroll: $attrs.infinite ? true : false
      });
    }

    return  {
      restrict: 'E',
      replace: true,
      scope: {
        title: '@',
        get: '@',
        showSubmitted: '&',
        infinite: '&',
        editor: '&'
      },
      controller: ClassroomContentCtrl,
      controllerAs: 'content',
      link: link,
      templateUrl:
'components/user/classroom/classroom-content/classroom-content.html'
    };
  }


  angular.module('app.user.classroom.content', [
    'ngCkeditor'
  ])
    .factory('ClassroomContent', ClassroomContent)
    .directive('appClassroomContent', ClassroomContentDirective)
  ;




On Fri, Sep 5, 2014 at 7:12 AM, Rob Koberg <[email protected]> wrote:

> I do something like what I pasted below.
>
> Recommendations is a service that is a subclass of the following PagedView
>
>   function RecommendationsCtrl($location, User, Data, Books,
> Recommendations) {
>
>     this.service = new Recommendations({
>       isInfiniteScroll: true,
>       loadData: Data.get()
>     });
>
>     this.user = User;
>     this.categoriesDropdown = Books.categoriesDropdown();
>     console.log('RecommendationsCtrl this', this);
>
>   }
>
>
> (disregard the timeago method if it offends you :) )
>
>
> (function () {
>
>   'use strict';
>
>   function PagedViewFactory($location, $timeout, Data) {
>
>     var PagedView = function (options) {
> //      console.log('PagedView options', options);
>       if (!options) {
>         return;
>       }
>
>       this.getUrl = options.path || $location.path();
>       this.isInfiniteScroll = options.isInfiniteScroll || false;
>
>       if (angular.isObject(options.loadData)) {
>         this.items = options.loadData.items;
>         this.pager = options.loadData.pager;
>
>
>         this.loading = false;
>         this.initLoad = true;
>         this.noItems = this.items.length;
>         this.noMoreItems = (this.pager.pages === 1);
>
>       } else {
>         this.items = false;
>         this.pager = false;
>         this.loading = false;
>         this.initLoad = false;
>         this.noItems = false;
>         this.noMoreItems = false;
>
>       }
>     }
>
>     PagedView.prototype.toString = function() {
>       return '[PagedView "' + this.getUrl + '"]';
>     };
>
>     PagedView.prototype.applyTimeago = function() {
>       $timeout(function() {
>         jQuery('abbr.timeago').timeago();
>       }, 0, true);
>     };
>
>     PagedView.prototype.set = function (items) {
>       this.items = items;
>     };
>
>     PagedView.prototype.get = function (pageNum) {
>       var self = this;
>       pageNum = pageNum || 0;
>       this.loading = true;
>
>       var options = {
>           params: {
>             page: pageNum
>           }
>         },
>         promise = Data.load(this.getUrl, options);
>
>       promise.success(function (data) {
> //console.log('PagedView.get promise data', data);
>         self.initLoad = true;
>         self.loading = false;
>
>         if (!self.isInfiniteScroll) {
>           self.noMoreItems = true;
>         }
>
>         self.pager = data.pager;
>         if (angular.isArray(self.items) && pageNum !== 0) {
>
>           angular.forEach(data.items, function (item) {
>             self.items.push(item);
>           });
>
>         } else {
>           self.items = data.items;
>         }
>         self.applyTimeago();
>       });
>     };
>
>     PagedView.prototype.nextPage = function () {
>       if (this.pager) {
>         if (this.pager.page === -1) {
>           this.noItems = true;
>         } else if (this.pager.page === (this.pager.pages - 1)) {
>           this.noMoreItems = true;
>         } else {
>           this.get(this.pager.page + 1);
>         }
>       } else {
>         this.get();
>       }
>     };
>
>     PagedView.prototype.getItemAt = function (itemIndex) {
>       return this.items[itemIndex];
>     };
>
>     return PagedView;
>   }
>
>   angular.module('app.pagedView', [
>     'infinite-scroll'
>   ])
>     .factory('PagedView', PagedViewFactory)
>   ;
>
> })();
>
>
> On Fri, Sep 5, 2014 at 6:49 AM, steven smock <[email protected]> wrote:
>
>> Ganaraj,
>>
>> Sounds like a fun problem, to me... but then, I just learned about it
>> this morning.  :-)
>>
>> How about this approach:
>>
>>    1. Define a type within your (singleton) service; you will use this
>>    for your "non-singleton service instances."
>>    2. Give your service a factory method which accepts context as an
>>    argument, and returns an instance of the type defined in (1).
>>       1. If you need access to other objects created by this factory,
>>       maintain a hash of them within your service, and then give the service 
>> some
>>       retrieval methods.
>>          1. You could even make this structure hierarchical, if you
>>          wanted to.
>>       3. Continue to inject the service as you are doing, relying
>>    primarily on its factory method; consume instances with your
>>    controller/directive.
>>
>> What do you think?
>>
>>
>> On Thursday, September 4, 2014 7:15:20 AM UTC-4, ganaraj P R wrote:
>>>
>>> Hi,
>>>
>>> We are facing an issue where we need to be sharing non singleton states
>>> between controllers. I have explained it in more detail in here
>>>
>>> http://stackoverflow.com/questions/25663978/sharing-
>>> non-singleton-state-between-controllers-angular-architecture
>>>
>>> I would welcome any discussion regarding this. As more and more apps get
>>> built with Angular and the more larger apps that get built with it - Things
>>> start getting larger and complicated - A community driven way of figuring
>>> out common architectural patterns and anti-patterns would be amazing.
>>>
>>>
>>>
>>> --
>>> Regards,
>>> Ganaraj P R
>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "AngularJS" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/angular.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to