Ionic. How inject ionicPlatform into the service?

2019-09-05 01:34发布

I'd like to inject $ionicPlatform abstraction into the service, but seemed I'm doing this wrong way. How should I use $ionicPlatform with service?

(function () {
    "use strict";
    angular.module('service', []).service('BBNService', ["$ionicPlatform", function ($http, $localStorage, $ionicPlatform) {

This code making $ionicPlatform undefined.

2条回答
在下西门庆
2楼-- · 2019-09-05 02:00

Inject ionic dependency & Remove $http if you not using it as follows,

 angular.module('service', ['ionic'])
   .service('BBNService', ["$localStorage", "$ionicPlatform", 
       function ($localStorage, $ionicPlatform) {
   }]);
查看更多
走好不送
3楼-- · 2019-09-05 02:12

It's undefined because you wrong the order. (use ionic.Platform)

Replace with this:

angular.module('service', [])
  .service('BBNService', ["$http", "$localStorage", 
     function ($http, $localStorage) {
       //use this
       var $ionicPlatform = ionic.Platform;

  }]);
查看更多
登录 后发表回答