This is a sample view I am working with:
<div my-directive="somevalue">
<input name="myField" ng-model="dataForMyField">
</div>
Below is the code for my custom directive:
app.directive('myDirective', function ($compile) {
return {
restrict: 'A',
template: `<div ng-transclude=""></div>
<div>SomeValue from directive <strong>{{ someReturnedValue }}</strong></div>`,
transclude: true,
controller: function($scope, $element, $attrs, $transclude) {
$scope.someReturnedValue = 'ValueFromDirective';
console.log('Name of input'); // myField
$scope.$watch('vm.ngModel', function(newValue, oldValue, scope) {
console.log('WOW! Input.ngModel changed', newValue); // world in the init
});
}
}
})
I am trying to figure out how to access the ngModel of the input field.
Feel free to check out this Plunker example associated with this question.