TypeError:$ ionicLoading.show(...)。那么它不是一个函数

时间:2017-01-25 06:52:58

标签: javascript angularjs ionic-framework

我试图在任何控制器中为访问离子加载器($ ionicLoading)创建工厂服务。然后发生了错误,

  

“TypeError:$ ionicLoading.show(...)。然后不是函数”

任何人都可以看到我出错的地方或错误!

控制器:

function ($scope, IonicLoader, $ionicLoading, $ionicPlatform) {
  // load ionic loader 
    IonicLoader.show().then(function(){
         // Do somenthing here

      });
  }

服务:

var IonicLoader = angular.module('IonicLoader.service', []);
IonicLoader.factory('IonicLoader', ['$ionicLoading', function($ionicLoading){
  // show the loader
  function show(template, duration) {
    // check and set template
    var template = ( typeof template == 'undefined' || template == false) ? '<ion-spinner icon="dots"></ion-spinner>' : template;
    var duration = ( typeof duration == 'undefined' ) ? 10000 : duration;
    return $ionicLoading.show({
      template: template,
      animation: 'fade-in',
      duration: duration,
    }).then(function(){
      console.log("The loading indicator is now displayed");
    });
  };
  // hide the loader
  function hide() {
    return   $ionicLoading.hide().then(function(){
      console.log("The loading indicator is now hidden");
    });
  };
  return {
    show: show,
    hide: hide
  }
}])

1 个答案:

答案 0 :(得分:0)

如果您使用的是离子版1.2。*请使用$scope.show = function() { $ionicLoading.show({ // The text to display in the loading indicator content: '<i class=" ion-loading-c"></i> ', // The animation to use animation: 'fade-in', // Will a dark overlay or backdrop cover the entire view showBackdrop: true, // The maximum width of the loading indicator // Text will be wrapped if longer than maxWidth maxWidth: 200, // The delay in showing the indicator showDelay: 500 }); }; $scope.hide = function(){ $ionicLoading.hide(); };

controller('LoadingCtrl', function($scope, $ionicLoading) {
 $scope.show = function() {
 $ionicLoading.show({
   template: 'Loading...',
   duration: 3000
 }).then(function(){
     console.log("The loading indicator is now displayed");
 });
};

$scope.hide = function(){
  $ionicLoading.hide().then(function(){
     console.log("The loading indicator is now hidden");
  });
 };
});

在1.3。*中,您可以将其用作承诺:

Include

请参阅docs