AngularJS ng-change not calling function
AngularJS ng-change not calling function
我正在尝试获取引导弹出窗口中的内容,以便在用户在电子邮件文本框中键入某些内容时进行更改。似乎ng-change没有进入方法updateToolTip()
。我是AngularJS的新手。任何建议不胜感激。
网页
<div ng-controller="LoginController">
<for name="form" ng-submit="login()">
<input type="email" name="email" ng-model="user.email" value="{{user.email}}" ng-change="updateToolTip()" popover="{{emailMessage}}" popover-trigger="focus" popover-placement="right" required>
<button class="btn btn-lg btn-primary btn-block" type="submit" ng-disabled="form.$invalid">Sign in</button>
</form>
</div>
.js
var loginModule = angular.module('loginModule', ['ui.bootstrap']);
// Controller for the login page
loginModule.controller('LoginController', ['$scope', '$http', function($scope, $http) {
$scope.emailMessage = 'test';
$scope.updateToolTip = function() {
$scope.emailMessage = 'asdfsadf';
console.log();
console.log(' inside function');
if($scope.user != null) {
console.log('user not null');
if($scope.user.email.$dirty && $scope.user.email.$error.email) {
console.log('email dirty and error');
$scope.emailMessage = 'Invalid Email!';
} else if($scope.form.email.$dirty && $scope.form.email.$error.required) {
console.log('emaildirty and required');
$scope.emailMessage = 'Email Required';
}
}
}
}]);
form
名称更改为 name="user"
。喜欢
<form class="form-signin" name="user" ng-submit="login()">
由于您使用像user.XXXX
这样的表单模型.
演示普伦克
[编辑]
我会像这样写验证:
<input
type="email"
name="email"
class="form-control"
placeholder="Email address"
ng-model="user.email"
popover="{{emailMessage}}"
popover-trigger="focus"
popover-placement="right"
required
>
<span class="error" ng-show="mailform.email.$error.required">required</span>
<span class="error" ng-show="mailform.email.$error.email">invalid email</span>
<input
type="password"
name="password"
class="form-control"
placeholder="Password"
ng-model="user.password"
value="{{user.password}}" required >
<span class="error" ng-show="mailform.password.$error.required">required</span>
演示 2 普伦克
也许这个例子也可能对你有所帮助: 演示 3 Plunker
相关文章:
- 直接在函数声明上使用function.prototype.bind
- jQuery:.click(function(){(element),collapse('show',f
- 如果连接类型为none,则Javascript Function Only警报
- onLoad function phonegap android
- reducers在redux中得到Function not Object,what'it’他错了
- WIll window.addEventListener(“加载”,function(),false);等待浏览器自动填
- $(document).ready和jQuery(function($)不工作;jQuery已定义,但脚本尚未定义;t进
- Javascript onunload function
- 在init function()中调用getElementById(“..”),而不是想用它做点什么的函数
- spyOn:应为间谍,但得到了Function
- (typeof variable === “function”) 和 jQuery.isFunction() 有什么区别
- this内部的值返回this.each(function(){})
- Calling VB.Net from Javascript
- 如何在JavaScript中创建类似于something.function()的函数
- 如何通过 Function.prototype.apply() 更改调用函数的参数
- 控制台中的“function floor(){[本机代码]}”是什么
- AngularJS ng-change not calling function
- javascript function-calling
- Calling VB.NET WebMethod Function from Javascript
- Calling both a function and an onpage anchor on a <button