0
저는 AngularJs에 완전히 새내기입니다.AngularJS에서 immedietaly 함수를 호출합니다.
Facebook 기능을 호출하는 ngClick의 좋은 예가 있습니다.
컨트롤러를 준비한 후에 프로그래밍 방식으로 registerWithFacebook 함수를 호출하고 싶습니다. 그것을위한 방법은 무엇입니까? http://jsfiddle.net/IgorMinar/Hxbqd/5/
angular.module('HomePageModule', []).service('facebookConnect', function($rootScope) {
this.askFacebookForAuthentication = function(fail, success) {
FB.login(function(response) {
if (response.authResponse) {
FB.api('/me', function() { $rootScope.$apply(success) });
} else {
$rootScope.$apply(function() {
fail('User cancelled login or did not fully authorize.')
});
}
});
}
});
function ConnectCtrl(facebookConnect, $scope, $resource) {
$scope.user = {}
$scope.error = null;
$scope.registerWithFacebook = function() {
facebookConnect.askFacebookForAuthentication(
function(reason) { // fail
$scope.error = reason;
}, function(user) { // success
$scope.user = user
});
}
// Tried this but no success
// $scope.registerWithFacebook();
}
ConnectCtrl.$inject = ['facebookConnect', '$scope', '$resource'];
감사
는 "페이지로드"에 의해 구체적으로 무엇을 의미합니까? 그리고 왜이 시점에서 실행해야합니까? –
저는 연습하고 registerWithFacebook을 수동으로 호출하기를 원합니다. "페이지로드"에 의해 "$ view ($ viewContentLoaded ', registerWithFacebook);와 같은 의미를 가졌습니다. 그러나 작동하지 않았습니다. – Cemo
@JoshDavidMiller 제가 원하는 것을 말하면서 제 질문을 편집했습니다. 감사. – Cemo