AngularJS - 功能不能用于ng-click [英] AngularJS - function not working on ng-click
问题描述
当用户使用ng-click进入时,我的范围函数login()不起作用,为什么不起作用?请帮助!
HTML
< a id =login -button1class =button button-assertive button-block icon-right ion-log-inng-click =login()> Entrar< / a>
Funcion on controller
($ scope,Auth,$ stateParams){
$。$' b $ scope.login = function(){
$ signin_email = $ scope.userloginForm.email。$ modelValue;
$ signin_password = $ scope.userloginForm.password。$ modelValue;
//登录
验证$ signInWithEmailAndPassword($ signin_email,$ signin_password)
.then(function(firebaseUser){
//$scope.message =User使用uid创建:+ firebaseUser.uid;
alert(firebaseUser.email +登录成功!);
})。catch(function(error){
alert(error.message);
//$scope.error = error;
});
};
]])
形式如下:
< form id =login-form1name =$ parent.userloginF ormclass =list>
< div class =spacerstyle =height:40px;>< / div>
< ion-list id =login-list1>
< label class =item item-inputid =login-input1>
< span class =input-label>电子邮件地址:< / span>
< input type =textname =emailng-model =member.emailplaceholder =>
< / label>
< label class =item item-inputid =login-input2>
< span class =input-label> Senha:< / span>
< input type =passwordng-model =member.passwordplaceholder =>
< / label>
< / ion-list>
< div class =spacerstyle =height:40px;>< / div>
< a id =login-button1class =button button-assertive button-block icon-right ion-log-inng-click =login()> Entrar< / a>
< / form>
尝试使用 $ scope .member.email
而不是 $ scope.userloginForm.email。$ modelValue
和 $ scope.member.password code>代替
$ scope.userloginForm.password。$ modelValue
里面 login
函数,导致这个属性从表单的输入中进行角度写入。当然,你的控制器的顶部,你应该有 $ scope.member = {}
。另外,我认为你的表单的 name
应该是 userloginForm
,而不是 $ parent.userloginForm
。还有一件事 - 如果你不需要,你不应该使用
ng-click()
来提交表单,你应该 ng-submit =login
在你的表单上,< button id =login-button1class =button button-assertive button-block icon-right ion-log-in type =submit>入门< / button>
my scope function "login()" is not working when the user enter with the "ng-click" , why is not working? please help!
HTML
<a id="login-button1" class="button button-assertive button-block icon-right ion-log-in" ng-click="login()" >Entrar</a>
Funcion on controller
.controller('loginCtrl', ['$scope', "Auth", '$state',
function ($scope, Auth, $stateParams) {
$scope.login = function() {
$signin_email = $scope.userloginForm.email.$modelValue;
$signin_password = $scope.userloginForm.password.$modelValue;
// sign in
Auth.$signInWithEmailAndPassword($signin_email, $signin_password)
.then(function(firebaseUser) {
//$scope.message = "User created with uid: " + firebaseUser.uid;
alert(firebaseUser.email + " logged in successfully!");
}).catch(function(error) {
alert(error.message);
//$scope.error = error;
});
};
}])
That is the form :
<form id="login-form1" name="$parent.userloginForm" class="list" >
<div class="spacer" style="height: 40px;"></div>
<ion-list id="login-list1">
<label class="item item-input" id="login-input1">
<span class="input-label">Email :</span>
<input type="text" name="email" ng-model="member.email" placeholder="">
</label>
<label class="item item-input" id="login-input2">
<span class="input-label">Senha :</span>
<input type="password" ng-model="member.password" placeholder="">
</label>
</ion-list>
<div class="spacer" style="height: 40px;"></div>
<a id="login-button1" class="button button-assertive button-block icon-right ion-log-in" ng-click="login()" >Entrar</a>
<a href-inappbrowser="/signup" id="login-button2" class="button button-positive button-block button-clear">Esqueceu sua senha?</a>
</form>
Try to use $scope.member.email
instead of $scope.userloginForm.email.$modelValue
and $scope.member.password
instead of $scope.userloginForm.password.$modelValue
inside login
function, cause into this properties Angular writes from form's inputs. Of course, an the top of your controller, you should have $scope.member = {}
. Also, I think your form's name
should be userloginForm
, not $parent.userloginForm
. And one more thing - if you don't have to, you should not use ng-click()
to submit form, you should ng-submit="login"
on your form and <button id="login-button1" class="button button-assertive button-block icon-right ion-log-in type="submit">Entrar</button>
这篇关于AngularJS - 功能不能用于ng-click的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!