Я пытаюсь получить содержимое в bootstrap popover для изменения, когда пользователь вводит что-то в текстовое поле электронной почты. Кажется, что ng-change не попадает в метод updateToolTip()
. Я совершенно новый для AngularJS. Любые советы приветствуются.AngularJS ng-change не вызывающая функция
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';
}
}
}
}]);
Вы можете создать plunker/jsfiddle таким образом мы можем увидеть его в действии? – jpmorin
@ Catfish, не входя в глубины вашего кода, используете ли вы JQuery? У меня были проблемы с двумя woking вместе и, наконец, переместил загрузку JS в нижний колонтитул страницы. – avrono
Не связано с вопросом, но при использовании ng-модели на входе нет необходимости устанавливать атрибут value, поскольку он будет обрабатываться нг-модель! – jpmorin