按钮未在AngularJs中显示

时间:2015-07-24 23:00:30

标签: javascript angularjs

我已经在后端用Django-rest写了一个前端Facebook登录代码进行验证。但是,我的HTML文件中的按钮属性未显示 这是AngularJS中我的文件(HTML)的代码



<!DOCTYPE html>
<html>
<head>
<title>Facebook Login JavaScript Example</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<meta charset="UTF-8">
</head>
<body>
<div id="fb-root">
</div>

<script>		
    //facebook here
    //***************************************************
    window.fbAsyncInit = function() {
	FB.init({
	    appId      : 'Not inserted app id here for security reasons',
	    status     : true,
	    xfbml      : true
        });
    };
    
    (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/all.js";
     fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
</ script>

<button ng-click="login_fb()">Login with facebook</button>
<script> 
angular.module("myApp").controller("UserCtrl", 
	['$scope','$location', 'Facebook',
        function($scope, $location, Facebook /*we will write this factory next*/){
        
        $scope.login_fb = function(){
           Facebook.login().then(function(response){
               //this is where we'll contact backend. for now just log response 
               console.log(response);
           });
        }
}]);
</ script>
<script>
angular.module("myApp").factory('Facebook', 
    ["$q", "$window", "$rootScope",
    function($q, $window, $rootScope) {
		 
	// since we are resolving a thirdparty response, 
        // we need to do so in $apply   
	var resolve = function(errval, retval, deferred) {
	    $rootScope.$apply(function() {
	        if (errval) {
		    deferred.reject(errval);
	        } else {
		    retval.connected = true;
	            deferred.resolve(retval);
	        }
	    });
        }

	var _login = function(){
	    var deferred = $q.defer();
            //first check if we already have logged in
	    FB.getLoginStatus(function(response) {
	        if (response.status === 'connected') {
	            // the user is logged in and has authenticated your
		    // app
		    console.log("fb user already logged in");
		    deferred.resolve(response);
		} else {
		    // the user is logged in to Facebook, 
		    // but has not authenticated your app
		    FB.login(function(response){
		        if(response.authResponse){
			    console.log("fb user logged in");
			    resolve(null, response, deferred);
			}else{
			    console.log("fb user could not log in");
			    resolve(response.error, null, deferred);
			}
		    });
		 }
	     });
			
	     return deferred.promise;
	}

	return{
		login: _login,
	};
}]);
</ script>

</body>
</html>
&#13;
&#13;
&#13;

有人可以告诉我为什么我的按钮没有显示出来。

1 个答案:

答案 0 :(得分:2)

</ script>不是有效的HTML代码。将这些更改为</script>