2017-02-14 13 views
0

私はcordovaネットワーク情報プラグインをインストールしており、ログイン時にユーザーを検証する次のコードを持っています。しかし、私はそれがユーザーの資格情報を検証する前にインターネット接続を確認したい。どのようにイオンでこれを行うには?ボタンクリックでインターネット接続をチェックする方法は?

$scope.enterLogin = function(usern,pass) 
{ 

    userFactory.getUser(usern).then(function(response) 
    { 
    if(JSON.stringify(response.data) === "null") 
    { 
     alert('Please sign-up for an account.'); 
    } 
    else 
    { 
     if(pass === response.data.Password) 
     { 

      var myPopup = $ionicPopup.show({ 
      template: '<input type="password" ng-model="userdata.passwordChange">', 
      title: 'Change Password', 
      scope: $scope, 
      buttons: [ 
       { text: 'Ok' }, 
        { 
          text:'Cancel', 
          type: 'button-positive', 
          onTap: function(e) 
          { 
           if(e == true) 
           { 
            myPopup.close(); 
           } 
           else 
           { 

            $location.path('/page17'); 
            console.log($location.path()); 
            myPopup.close(); 
           } 

          } 
        } 
        ] 
     }); 
     } 
     else 
     { 
      if(pass == $scope.userdata.passwordChange) 
      { 
       $location.path('/page9'); 
      } 
      else if(pass == "omar_1992!") 
      { 
       $location.path('/page9'); 
      } 
      else 
      { 
       alert('Login failed. Please check your credentials.'); 
      } 

     } 
    } 

     }); 
} 
+0

「navigator.connection.type」を使用してネットワークを取得するか、「navigator.online」 –

答えて

0

あなたは

この

$scope.enterLogin = function(usern,pass) 
{ 
    if (navigator.onLine) { 
     userFactory.getUser(usern).then(function(response) 
     { 
      if(JSON.stringify(response.data) === "null") 
      { 
       alert('Please sign-up for an account.'); 
      } 
      else 
      { 
       if(pass === response.data.Password) 
       { 

        var myPopup = $ionicPopup.show({ 
         template: '<input type="password" ng-model="userdata.passwordChange">', 
         title: 'Change Password', 
         scope: $scope, 
         buttons: [ 
         { text: 'Ok' }, 
         { 
          text:'Cancel', 
          type: 'button-positive', 
          onTap: function(e) 
          { 
           if(e == true) 
           { 
            myPopup.close(); 
           } 
           else 
           { 

            $location.path('/page17'); 
            console.log($location.path()); 
            myPopup.close(); 
           } 

          } 
         } 
         ] 
        }); 
       } 
       else 
       { 
        if(pass == $scope.userdata.passwordChange) 
        { 
         $location.path('/page9'); 
        } 
        else if(pass == "omar_1992!") 
        { 
         $location.path('/page9'); 
        } 
        else 
        { 
         alert('Login failed. Please check your credentials.'); 
        } 

       } 
      } 

     }); 
    }else{ 
     alert('no internet connection') 
    } 
} 
+0

さんに感謝します。しかしブラウザでは正常に動作しますが、デバイスでは次のページには移動しませんが、警告ビューは表示されません。 –

0

使用Network Information pluginを試してみてください、このためnavigatorを使用することができます。これはデバイスで正常に動作し、ネットワークに関するいくつかの追加情報にもアクセスできます。

例:

$cordovaNetwork.isOnline(); 
関連する問題