Ion-toggle not changing states after user cancels option


#1

I have a toggle button that triggers a Facebook login for the user. It pretty much all works. Except that when the user cancels the login, I see the console message say “user cancelled login” and then reset the ion-toggle back to false/off - but it won’t change states but I do see the console.log message “In DisableFB” so I know the function/function call are working. If I leave the page and come back, it then shows off.

  <ion-toggle id="settings_FB" ng-model="fbItem.checked" ng-change="setFB()">
    Facebook Enabled:
  </ion-toggle>

  $scope.disableFB = function () {
    $scope.fbItem = {checked : false } ;
    console.log("In DisableFB") ;
  }

  $scope.setFB = function() {
    if ($scope.fbItem.checked == true) {
      alert("After logging into FB, you may need to set FB permissions to allow the app to interact with your FB page.") ;
      var fbLoginSuccess = function (userData) {
        ...some code ...
        facebookConnectPlugin.getAccessToken(function(token) {
       ....some code....
        }, function(err) {
          $scope.disableFB() ;
          console.log("FB: error retrieving token: " + err);
        });
      }
      
      facebookConnectPlugin.getLoginStatus(
        function(response) {
          if (response.status == "connected") {
             ...some code...
          } else {
            facebookConnectPlugin.login(["public_profile"],
              fbLoginSuccess,
              function (error) { 
                 $scope.disableFB() ;  // *** this is the line that fires when user cancels.***
                 console.log(error) ;
              }
            );
          }
        },function(error) {
          $scope.disableFB() ;
          console.log(response) ;
        }
  );
} else {
  facebookConnectPlugin.logout(
    function(response) {
      console.log("FB Logged out") ;
      ...some code....
      $scope.disableFB() ;
    },
    function(error) {
      console.log("FB Logout Error: "+ error.message) ;
      ...some code...
      $scope.disableFB() ;
    }
  ) ;
}

}


#2

Try:

$scope.fbItem.checked = false; instead of $scope.fbItem = {checked : false } ;

Also you are missing all the closing brackets, add )}


#3

@antonfire thanks for the fast response. I corrected the closing brackets.

I did try your solution, its not working either. in fact, that was the original line in the facebook error responses. But because it wasn’t working I thought that maybe $scope wasn’t being passed properly so then I moved the toggle reset to false to an external function (as you see above).