2017-01-25 4 views
0

私はどのコントローラでもionic loader($ ionicLoading)にアクセスするためのファクトリサービスを作成しようとしていました。エラーが発生しました

"TypeError: $ionicLoading.show(...).then is not a function"

誰かが私が間違っているか、エラーが発生しているのを誰でも見ることができます!

コントローラ:

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 
 
    } 
 
}])

+0

私が見つけることができるものの、おそらく問題ではないものは次のとおりです:1. 'duration:duration、'は終わりのコンマを持つべきではありません。 2. angular.module( 'IonicLoader.service'、[]); 'イオン依存性を含むべきではありませんか? 3.あなたはモジュールを定義する 'var IonicLoader'を持っています。そしてコントローラに' IonicLoader'と同じ名前の別のパラメータを注入します。おそらく矛盾があります –

+0

hello Ovidiu、助けてくれてありがとう。 私はあなたが言及したように試みましたが、それはまだ動作していません。私はそれが何であるか分かりません。 : -/ –

+0

こんにちはOvidiu、もう一度ありがとう!私はその誤りの理由を知りました。それはionic-angular.jsバージョンに関するものです。 Ionic v1.3.2のための作品! –

答えて

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(); 
}; 

1.3では*あなたは約束としてそれを使用することができます。

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"); 
    }); 
}; 
}); 

docsを参照してください。

関連する問題