javascript - AngularJS with Facebook SDK -


this question has answer here:

i have problem angularjs.

i want return values within facebook sdk functions not let me them in variables.

the "perfil_nombre" , "perfil_foto" variables returned "undefined" , wish send scope.

any chance? i'm totally lost.

excuse bad english.

login.controller('inicio_ctrl', function($scope, $http, $timeout, $window) {       var laspaginas;       var response;       var perfil_foto;       var perfil_nombre;       var resp;       $scope.fblogin = function()       {         fb.login(function(response)          {             if(response.authresponse)              {                 fb.api('/me', function(response)                  {                     perfil_nombre = response.name; //<<<<<--------                     fb.api('/me/picture?redirect=false', function(resp)                      {                        perfil_foto = resp.data.url; //<<<<<--------                     });                 });             }              else              {              console.log('user cancelled login or did not authorize.');             }         },          { scope: 'email, public_profile, manage_pages,publish_pages,read_insights,user_friends, publish_actions'});         $scope.perfil_foto = perfil_foto; //<<<<<-------- undefined         $scope.perfil_nombre =  perfil_nombre; //<<<<<-------- undefined }); 

angular designed mvc or mv* framework. such better separate logic service , inject service controller. way can prevent negative interactions between angular , other frameworks. can difficult anticipate how angular interact outside libraries.

the simplest way make function work using javascript , wrap in .factory or .service.

for example

(function(){     'use strict';     login.factory('fbservice', fbservice);      fbservice.$inject = [(/*what ever dependencies needed*/)];     function fbservice(/*what ever dependencies needed*/){         //build profile object (i assume perfil translates profile in english)         var profileobject;         //add javascript logic here           //create getters obtain data         function getfoto(){             return profileobject.foto;         }          //expose getter         return {getfoto: getfoto}     } })();  (function(){     'use strict';     login.controller('inicio_ctrl', inicioctrl);      inicioctrl.$inject = ["$scope", "$http", "$timeout", "$window", "fbservice"];     function inicioctrl($scope, $http, $timeout, $window, fbservice){         var ctrl = this;          ctrl.login = function(){             ctrl.perfil_folo = fbservice.getfoto();         }     } })(); 

if can javascript work outside of angular allow preserve work , integrate angular


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -