0

我试图让引导弹出窗口中的内容在用户在电子邮件文本框中键入内容时进行更改。似乎 ng-change 没有进入 method updateToolTip()。我是 AngularJS 的新手。任何建议表示赞赏。

html页面

<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';
            }
        }
    }
}]);
4

1 回答 1

4

form将名称更改为name="user"。像

 <form class="form-signin" name="user" ng-submit="login()">

由于您使用表单模型,例如user.XXXX.

演示Plunker

[编辑]

我会这样写验证:

<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>

演示 2Plunker

也许这个例子也可以帮助你:Demo 3Plunker

于 2013-11-08T23:18:19.497 回答