单击按钮时如何更改ng-view

时间:2017-10-23 10:27:26

标签: javascript angularjs facebook

我希望在FB Auth为真时改变我的观点,并且我正在尝试这个

app.controller('View1Ctrl', ['$scope','$location',function($scope) {
$scope.name="Inice de Sesion por favor";
$scope.FBLogin=function(){
FB.login( function(response){
   if(response.authResponse){
      //$scope.view="#!/view2"
      $location.path("#!/view2");
      $scope.name="Sesion iniciada";
      console.log("Bienvenido! Cargando tu informacion...");
      FB.api('/me',function(response){
        console.log("Es bueno verte de nuevo, " + response.name +   
'.');
        console.log(response);
        var tokenAcceso=FB.getAuthResponse();
        console.log(tokenAcceso);
      });
    }else{
      console.log("Error al autentificar al usuario");
    }
});
};
}]);

并在我的html中

<div class="boton-agregar" ng-controller="View1Ctrl">
<h1>{{name}}</h1>
<ons-button ng-click="FBLogin()">Iniciar sesion con FaceBook</ons-
button>
</div>
</ons-page>

所以问题是,当我点击按钮时,如何更改视图以及我在fb auth部分中的功能响应是否为真?

2 个答案:

答案 0 :(得分:0)

之后

var tokenAcceso=FB.getAuthResponse();

DO

$location.path('/yourview');

答案 1 :(得分:0)

.controller('LoginController', ['$location, function ($location) {
    $scope.FBLogin=function(){
FB.login( function(response){
   if(response.authResponse){
      //$scope.view="#!/view2"
      $location.path("#!/view2");
      $scope.name="Sesion iniciada";
      console.log("Bienvenido! Cargando tu informacion...");
      FB.api('/me',function(response){
        console.log("Es bueno verte de nuevo, " + response.name +   
'.');
        console.log(response);
        var tokenAcceso=FB.getAuthResponse();
        console.log(tokenAcceso);
        $location.path('/yourcomponent'); 
      });
    }else{
      console.log("Error al autentificar al usuario");
    }
});
};
}