AngularJS 错误:TypeError:v2.login 不是函数 [英] AngularJS error: TypeError: v2.login is not a function

查看:43
本文介绍了AngularJS 错误:TypeError:v2.login 不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在单击登录按钮时调用登录功能,但一直在标题中收到错误消息.有人可以指出我脚本中的错误吗?

login.js 代码如下:

/*全局 Firebase,角度,控制台*/'使用严格';//使用 AngularFire 模块创建一个新应用var app = angular.module("runsheetApp");app.controller("AuthCtrl", function ($scope, $firebaseAuth) {var ref = new Firebase("https://xxxxx.firebaseio.com");函数登录(){ref.authWithPassword({电子邮件:xxxxx",密码:xxx"},函数(错误,authData){如果(错误){console.log("登录失败!", error);} 别的 {console.log("已通过payload成功验证:", authData);}});}});

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script>

login.html 的代码也在下面:

<form class="form-signin"><h2 class="form-signin-heading" style="text-align: center">请登录</h2><input type="text" class="form-control" name="username" ng-model = "username" placeholder="Email Address" required="" autofocus=""/></br><input type="password" class="form-control" name="password" ng-model = "password" placeholder="Password" required=""/></br><button class="btn btn-lg btn-primary btn-block" type="submit" ng-click="login()">登录</button></表单>

解决方案

就我而言,我遇到了与您完全相同的问题.但是,遇到 gkalpak 的回答 对这种情况帮助了我.

结果我调用的是 addBuddy() 函数,来自一个名为addBuddy"的表单.解决方案是更改两个事物中的任何一个的名称,以使一个事物脱颖而出或与另一个事物区分开来.我将表单的名称更改为addBuddyForm",瞧!我的功能奏效了!

这是我的案例片段:

...<button class="btn btn-sm btn-info" ng-click="addBuddy()>提交</button>

哪个,我改为:

...<button class="btn btn-sm btn-info" ng-click="addBuddy()>提交</button>

...它奏效了!:)

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("https://xxxxx.firebaseio.com");
    function login() {
        ref.authWithPassword({
            email    : "xxxxx",
            password : "xxxx"
        }, function (error, authData) {
            if (error) {
                console.log("Login Failed!", error);
            } else {
                console.log("Authenticated successfully with payload:", authData);
            }
        });
    }
});

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></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="" />
        </br>
      <input type="password" class="form-control" name="password" ng-model = "password" placeholder="Password" required=""/>
        </br>
      <button class="btn btn-lg btn-primary btn-block" type="submit" ng-click="login()">Login</button>   
    </form>
  </div>

解决方案

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! :)

这篇关于AngularJS 错误:TypeError:v2.login 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆