在 ionic 中使用 ngStorage 作为数组

using ngStorage as array in ionic

正在尝试转换此

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

有效,除非 运行 在 phone cordova 上,它 return 只有两项

所以我正在尝试使用 ngStorage 来存储数组

.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);

但无法在浏览器 emu 上运行,出现以下错误

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 在 http://localhost:8100/lib/ionic/js/ionic.bundle.js:8762:12

服务中没有$scope$scope 仅在视图相关组件中需要,服务与视图无关。

$rootScope可以注入服务,但不适合存储数据。它更常用于广播事件的服务

虽然您可以使用变量来定义不需要直接绑定到的东西 this

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

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