Am creating a custom directive which takes a simple template consist of input type textarea am assigning the ng-model to ngmodel and creating a link function in this am creating a on change event where am trying to get the ngmodel value but its printing undefined, please help me to resolve this issue, here by posting the link which I have tried do corrections if required plunkr ,code starts here
// Code goes here
var app = angular.module('myApp',[]);
app.directive('markdownEditor', function () {
return {
restrict: 'E',
scope: {
ngModel: "="
},
require:'ngModel',
template:
'<textarea ng-model="ngModel"></textarea>' +
'{{ ngModel}}',
link:function(scope,ele,attr,ctrl){
ele.on("keydown",function(){
alert(scope.ctrl)
})
}
}
});
app.controller('DemoCtrl', function ($scope) {
var x= $scope.markdown;
});
<html ng-app="myApp">
<body>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
<div ng-controller="DemoCtrl">
<h3>Markdown editor</h3>
<markdown-editor ng-model="markdown" name="markdown"></markdown-editor>
</div>
</body>
</html>