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')
.directive('infoVal', myVal);
function myVal() {
return {
link: function(scope, element, attrs, ctrl){
console.log("Ng Model value");
console.log(attrs.ngModel.$viewValue);
}
}
};
HTML input:
<input type="text"
class="form-control"
name="info"
ng-model="formCtrl.infor"
info-val>
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.