私は自分のコントローラから変数にアクセスしたいので、私は自分のサービスでそれを使うことができます!私は変数をグローバルにするとサービスにアクセスできると思っていましたが、heheはうまくいきません。変数はショップ btwです!私は、変数を作成していますのはここコントローラからサービスへの変数へのアクセス|角度1.5
は次のとおりです。ここで
$scope.$on('$ionicView.enter', function (e) {
ecommercer.getData().then(function (s) {
$scope.shops = s.vendors
$scope.categories = s.categories
$ionicScrollDelegate.resize()
if ($stateParams.id && $stateParams.id.length > 1) {
$ionicTabsDelegate.showBar(false)
ecommercer.saveShopById($stateParams.id)
$state.go('tab.ecommerce.shop')
}
})
})
(同じファイル)私は私の変数を使用していところである:私は同じを作成するのはここ
$scope.$watch('selectedCategory.name', function (newval, oldval) {
if ($scope.selectedCategory.name != undefined) {
$scope.shops = ecommercer.filterByCategory(newval.id)
} else {
$scope.shops = ecommercer.filterByCategory(null)
}
})
です私のサービス・ファイル内の変数:私は私のサービスでそれを使用しようとしているとき、最後に
app.service('ecommercer', function (eapi, $q, storage, $http, endpointHandler, $state, $rootScope, $filter) {
var products, categories, vendors, shops
は、ここにある:
function filterByCategory(categoryid, shops) {
if (!categoryid) return shops
console.log(shops);
var newlist = []
for (var s in shops) {
if (shops[s].category.split(',').length > 0) {
for (var c in shops[s].category.split(',')) {
if (shops[s].category.split(',')[c] == categoryid) {
newlist.push(shops[s])
}
}
}
}
return newlist
}