AngularJS ng-change not calling function

AngularJS ng-change not calling function

本文关键字:function calling not ng-change AngularJS      更新时间:2023-09-26

我正在尝试获取引导弹出窗口中的内容,以便在用户在电子邮件文本框中键入某些内容时进行更改。似乎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