2016-07-20 9 views
0

私のデータが受信されるまで、イオンローダーを表示しようとしています。私はいくつかの解決策を確認したが、うまくいかなかった。これは私のコードです。

$ ionicLoading.show({ コンテンツ: '読み込み'、 アニメーション: 'フェードイン' showBackdrop:真、 のmaxWidth:200、 showDelayを0 })。私は呼ん

$scope.allcourses = CourseFactory.FindFreeCourses($scope.search).then(function(result){ 
     console.log(result); 
     $scope.allfreestadiums = result; 
     $ionicLoading.hide(); 
    }, function(error){ 
     console.log(error); 
     $ionicLoading.hide(); 
     $ionicLoading.show({ 
      template: 'Network Error', 
      scope: $scope 
     }); 
     $timeout(function() { 
      $ionicLoading.hide(); 
     }, 100); 
    }) 

のみ

$ scope.allcourses = CourseFactory.FindFreeCourses($のscope.search)。

うまくいきましたが、画面に表示される前に読み込みを表示します。 何が問題なのでしょうか?

答えて

1

console.log()は、ブラウザよりもデバイス/エミュレータの動作が異なる場合があります。ブラウザは通常、オブジェクトをparam(console.log(obj))として受け入れますが、これはデバイス上で問題です。あなたは代わりにこれを試してみたいことがあります。また呼ばれたときに、コンソールが定義されていないためにconsole.log()関数が失敗している可能性があり console.log("some message", JSON.stringify(obj))

$ionicLoading.show({ content: 'Loading', animation: 'fade-in', showBackdrop: true, maxWidth: 200, showDelay: 0 }); 

$scope.allcourses = CourseFactory.FindFreeCourses($scope.search).then(function(result){ 
    $ionicLoading.hide(); 
    $scope.allfreestadiums = result; 
    console.log("success", JSON.stringify(result)); 
}, function(error){ 
    $ionicLoading.hide(); 
    console.log("error", JSON.stringify(error)); 
}) 

。これは、テストする方法と、環境がデフォルトでコンソール変数を公開するかどうかによって異なります。これはSchrodingerのシナリオです。デベロッパーコンソールを開くと、一部のブラウザーでコンソール変数が定義されているため、問題が解消されます。 console.log()の呼び出しをコメントアウトし、$ ionicLoading.hide()をそれらのコールバックの先頭に移動してください。

それとも、そのwindow.consoleが(にconsole.logを呼び出す前に存在して確認できます)ここに示したように:

$ionicLoading.show({ content: 'Loading', animation: 'fade-in', showBackdrop: true, maxWidth: 200, showDelay: 0 }); 

$scope.allcourses = CourseFactory.FindFreeCourses($scope.search).then(function(result){ 
    $ionicLoading.hide(); 
    window.console && console.log("success", JSON.stringify(result)); 
    $scope.allfreestadiums = result; 
}, function(error){ 
    $ionicLoading.hide(); 
    window.console && console.log("error", JSON.stringify(error)); 
}) 
+0

こんにちは、答えに感謝しかし、私は永遠にその積載まだuは述べたすべてのものを試してみましたけど。私はconsole.logを削除し、コールバックの上にhideを置いても、まだ動作しませんでした。ブラウザの問題か、ファクトリメソッドか?なぜなら私が$ scope.allcourses = CourseFactory.FindFreeCourses($ scope.search)だけを呼び出すと問題なく動作するからです。 –

+0

Angular promisesで作業しましたか? CourseFactory.FindFreeCourses()は約束を返す必要があり、その約束は解決する必要があります。私の推測では、FindFreeCourses()では、それらの.then()コールバックに到達するために必要な約束を解決していないということです。 FindFreeCourses()の中では、次のようなことをしてください: 'var q = $ q.defer();/*あなたのコースルックアップコールバックを行う*/q.resolve();/* ... */return q.promise; ' – voodoodrul