Hi. this is my code. I need get the value of the input text, but I only can get the value, when the value on the input text ischanged. How can get the value of the input text without need change.(get initially the value of the input text)
I want to do something very generic, that I can reuse it in any controller. Have a certain number of fields and validate them, so I do not want to always get the value of the variable "number".
I want to reuse this directive on any controller. I will not always have the $ scope.numero variable. How can I get the value of the text field without typing scope.numero in the directive?
var app = angular.module('app', []);
app.controller('appCtrl', function ($scope) {
$scope.numero=100500
});
app.directive('validate', function () {
return {
restrict: 'AE',
require: 'ngModel',
link: function (scope, element, attrs, ngModel) {
if (!ngModel){
return;
}
ngModel.$parsers.push(function(val){
if ((val>10) && (val<20)){
element.removeClass("wrong");
element.addClass("correct");
} else {
element.removeClass("correct");
element.addClass("wrong");
}
ngModel.$render();
})
}
};
});