directive ngModel require

by Aswin Devarajan

HTML

<input type="text" test-dir ng-model="test" value>

JavaScript

var app = angular.module('myApp', []);
app.controller('mainCtrl', ['$scope', function($scope) {
  $scope.test = 'viva';
}]);


app.directive('testDir', function() {
  return {
    scope: {
    	
    },
    require: '?^ngModel',
    restrict: 'A',
    link: function(scope, elem, attrs, ngModel) {
		
    elem.bind('blur change keyup', function(){
    	console.log('logging value: ',ngModel.$viewValue);
    });
		
    }
  };
});