3

trying to convert this

.service('dataStore', function($localStorage,$scope){
    this.entfeeds=[];
    this.topfeeds=[];
    this.intfeeds=[];
})
.controller('GenFeedCtrl', function ($scope,....
     $scope.feeds = FeedList.get(feedSources, dataStore.topfeeds);

which works ,except when run on phone cordova ,it return only two item

so am trying to use ngStorage to store the array

.service('dataStore', function($localStorage,$scope){
    $scope.$storage = $localStorage.$default({
        etf:[],
        tpf:[],
        itf:[]
    });

    this.entfeeds=$storage.etf;
    this.topfeeds=$storage.tpf;
    this.intfeeds=$storage.itf;})

    .controller('GenFeedCtrl', function ($scope,....
     $scope.feeds = FeedList.get(feedSources, dataStore.topfeeds);

but not working on browser emu ,gives the following error

Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <-     dataStore

http://errors.angularjs.org/1.3.13/$injector/unpr?p0=copeProvider%20%3C-%20%24scope%20%3C-%dataStore at http://localhost:8100/lib/ionic/js/ionic.bundle.js:8762:12

rudolph1024
  • 962
  • 1
  • 12
  • 32

1 Answers1

4

There is no $scope in a service. $scope is only needed in view related components and a service has no connection to the view.

$rootScope can be injected into a service, but it is not appropriate for storing data. It would more commonly be used in a service to broadcast events

You can use variables though to define things that don't directly need to be bound to this

.service('dataStore', function($localStorage){
    var $storage = $localStorage.$default({
        etf:[],
        tpf:[],
        itf:[]
    });

    this.entfeeds=$storage.etf;
    this.topfeeds=$storage.tpf;
    this.intfeeds=$storage.itf;
})
charlietfl
  • 170,828
  • 13
  • 121
  • 150