AngularJS error: TypeError: v2.login is not a function


I would like to call the login function when I click the login button but keep getting the error message in the title. Can someone point out the error in my script?

login.js code below:

/*global Firebase, angular, console*/

'use strict';
// Create a new app with the AngularFire module
var app = angular.module("runsheetApp");

app.controller("AuthCtrl", function ($scope, $firebaseAuth) {
    var ref = new Firebase("");
    function login() {
            email    : "xxxxx",
            password : "xxxx"
        }, function (error, authData) {
            if (error) {
                console.log("Login Failed!", error);
            } else {
                console.log("Authenticated successfully with payload:", authData);
<script src=""></script>

And the code for login.html is also below:

<div class="container" style="max-width: 300px">
    <form class="form-signin">       
      <h2 class="form-signin-heading" style="text-align: center">Please Sign In</h2>
      <input type="text" class="form-control" name="username" ng-model = "username" placeholder="Email Address" required="" autofocus="" />
      <input type="password" class="form-control" name="password" ng-model = "password" placeholder="Password" required=""/>
      <button class="btn btn-lg btn-primary btn-block" type="submit" ng-click="login()">Login</button>   


In my case, I was having an exact same issue as yours. However, coming across gkalpak’s answer to such a scenario helped me out.

Turned out to be what I was calling was addBuddy() function, from a form named “addBuddy”. The solution was to change the name of either of the two things to make one stand out or differentiable from the other. I changed the name of the form to “addBuddyForm” and voila! My function worked!

Here’s a snippet of my case:

<form name="addBuddy" class="form-horizontal" novalidate>
<button class="btn btn-sm btn-info" ng-click="addBuddy()>Submit</button>

Which, I changed to:

<form name="addBuddyForm" class="form-horizontal" novalidate>
<button class="btn btn-sm btn-info" ng-click="addBuddy()>Submit</button>

…and it worked! 🙂

Answered By – r0u9hn3ck

Answer Checked By – Katrina (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.