Иван Продайко Иван Продайко - 7 months ago 11
Javascript Question

Controller function doesn't work in Angular.js

Hello to everyone reading this!
I have a problem executing function in my Ctrl.

I tried to do some alerts, console.log and search here for answer but didn't find exect same problem, just similar.
I'll be grateful to everyone helping me solve this problem)

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>




Answer

Try changing your html with this one, in your ng-click you were referring to SignUp instead of 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>