I am a beginner in Angularjs, so please correct me if I am wrong in understanding.
Firstly, below is my code. What I am trying is to create a custom directive for input validation.
For example:
<input drtooltip-message type="text" ng-minlegth="3"> //if the length of the input value is less than 3 a tooltip with custom message should be shown
<input drtooltip-message type="text" ng-maxlegth="5">////if the length of the input value is greater than 5 a tooltip with custom message should be shown
Html
<div ng-app="validationApp" ng-controller="mainController">
<input drtooltip-message type="text" name="name" class="form-control" ng-model="user.name" required tooltip="Tooltip on left" tooltip-placement="top" ng-minlength="5" ng-maxlength="8" >
</div>
Js
var validationApp = angular.module('validationApp', ['ui.bootstrap']);
validationApp.controller('mainController', function($scope) {
});
validationApp.directive('drtooltipMessage', function () {
return {
restrict: 'A',
template: '<input tooltip tooltip-placement="top" >',
replace: true,
require: 'ngModel',
link: function (scope, element, attrs, ctrl) {
ctrl.$parsers.push(function (viewValue) {
alert(viewValue);//always getting 'undefined'
}
}
};
});
I am expecting the value entered in the input box as alert value, but am getting 'undefined'.
Reference: What's the difference between ngModel.$modelValue and ngModel.$viewValue