2016-04-26 87 views
0

大家好! 我在我的Ctrl中執行功能時出現問題。控制器功能在Angular.js中不起作用

我試着做一些警報,console.log和搜索這裏的答案,但沒有找到exex相同的問題,只是類似。 我會感謝大家幫我解決這個問題)

HTML

// ctrls.js 
 

 
var gameApp = angular.module('gameApp'); 
 

 
var AuthorizationCtrl = gameApp.controller('AuthorizationCtrl', function($scope) { 
 
    $scope.email = email.value; 
 
    $scope.password = password.value; 
 
    $scope.signUp = function() { // this function isn't executed when I hope it to be 
 
     console.log($scope.email, $scope.password); 
 
     gameFactory.signUp(email, password).then(function() { 
 

 
     }); 
 
    }; 
 
}); 
 

 

 
// services.js 
 
function Factory(FBMSG, $firebaseArray, $firebaseAuth) { 
 
    var events = {}, 
 
     ref = new Firebase(FBMSG), 
 
     games = $firebaseArray(ref), 
 
     auth = $firebaseAuth(ref); 
 

 
    events.getAllGames = function() { 
 
     return games.$loaded(); 
 
    }; 
 

 

 
    events.signUp = function(email, password) { 
 
     return auth.createUser({ 
 
      email: email, 
 
      password: password 
 
     }); 
 
    }; 
 

 
    return events; 
 

 
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<!-- ng-view --> 
 
<div ng-controller="AuthorizationCtrl" style="background-color: rgba(0, 0, 0, .5); width: 40%; margin:auto"> 
 
    <form> 
 
     <div class="form-group"> 
 
      <label for="email">Email address</label> 
 
      <input ng-model='email' type="email" class="form-control" id="email" placeholder="Email" required> 
 
     </div> 
 
     <div class="form-group"> 
 
      <label for="password">Password</label> 
 
      <input ng-model="password" type="password" class="form-control" id="password" placeholder="Password" required> 
 
     </div> 
 
     <a href="">Forgot your password?</a> 
 
     <div> 
 
      <button ng-click="SignUp()">SignUp</button> <!-- Problem!!! --> 
 
     </div> 
 
    </form> 
 
</div>

+0

你在哪裏得到'email.value'? 「'$ scope.email = email.value'」 – theblindprophet

+0

+0

signUp而不是SignUp。你的帽子錯了,結帳ng-click –

回答

0

試着用這一個改變你的HTML,在你的NG-點擊你指的註冊而不是signup

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
<!-- ng-view --> 
<div ng-controller="AuthorizationCtrl" style="background-color: rgba(0, 0, 0, .5); width: 40%; margin:auto"> 
    <form> 
     <div class="form-group"> 
      <label for="email">Email address</label> 
      <input ng-model='email' type="email" class="form-control" id="email" placeholder="Email" required> 
     </div> 
     <div class="form-group"> 
      <label for="password">Password</label> 
      <input ng-model="password" type="password" class="form-control" id="password" placeholder="Password" required> 
     </div> 
     <a href="">Forgot your password?</a> 
     <div> 
      <button ng-click="signUp()">SignUp</button> <!-- signUp instead of SignUp!!! --> 
     </div> 
    </form> 
</div> 
+0

非常感謝!這是愚蠢的錯誤。 ((((( –

+0

沒問題!:))請記住接受提供的答案。如果您有任何其他問題,請給我一個直接的消息,我會很樂意幫助你! –