I\'m trying to get the value from ngModel from my input through a directive, but I can\'t get the value.
Here is my code:
angular
.module(\'myapp\')
You're very close, but you need to make a minor adjustment to your directive in order to be able to pass and access the ng-model
item.
angular
.module('myapp')
.directive('infoVal', myVal);
function myVal() {
return {
require: 'ngModel',
link: function(scope, element, attrs, ngModel) {
console.log('ng-model value', ngModel.$viewValue);
}
}
};