gpt4 book ai didi

angularjs - 在 ionic 中使用 ngStorage 作为数组

转载 作者:行者123 更新时间:2023-12-01 12:33:01 24 4
gpt4 key购买 nike

试图转换这个

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

有效,除了在手机 cordova 上运行时,它只返回两项

所以我尝试使用 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 仅在 View 相关组件中需要,服务与 View 无关。

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

虽然您可以使用变量来定义不需要直接绑定(bind)到 this

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

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

关于angularjs - 在 ionic 中使用 ngStorage 作为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31816184/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com