I'm trying to get the content in a bootstrap popover to change when the user types something in the email text box. It seems that ng-change is not getting into the method updateToolTip()
. I'm brand new to AngularJS. Any advice is appreciated.
html page
<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';
}
}
}
}]);
I'm trying to get the content in a bootstrap popover to change when the user types something in the email text box. It seems that ng-change is not getting into the method updateToolTip()
. I'm brand new to AngularJS. Any advice is appreciated.
html page
<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';
}
}
}
}]);
Share
Improve this question
asked Nov 8, 2013 at 22:53
CatfishCatfish
19.3k60 gold badges213 silver badges358 bronze badges
8
- Can you create a plunker / jsfiddle so we can see it in action? – jpmorin Commented Nov 8, 2013 at 22:56
- @Catfish without going into the depths of your code, are you using Jquery as well ? I had problems with the two woking together and finally moved the JS loading into the page footer – avrono Commented Nov 8, 2013 at 22:57
- Not related to the question, but when using ng-model on an input, there is no need to set the value attribute as it will be handled by ng-model! – jpmorin Commented Nov 8, 2013 at 22:57
- can you post the plete HTML ? – avrono Commented Nov 8, 2013 at 22:59
- plnkr.co/edit/2pPR60ybLwv1VvIudy8m?p=preview – Catfish Commented Nov 8, 2013 at 23:01
1 Answer
Reset to default 4Change form
name to name="user"
. Like
<form class="form-signin" name="user" ng-submit="login()">
Since you use form model like user.XXXX
.
Demo Plunker
[EDIT]
I would write validation like this:
<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>
Demo 2 Plunker
And maybe this example might help you as well: Demo 3 Plunker