Last active
August 29, 2015 13:55
-
-
Save danielpsf/8786645 to your computer and use it in GitHub Desktop.
Just to understand more about binding an event watch to some element into a directive. you can see here: http://jsbin.com/EluKodAC/3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('myApp', []) | |
.controller('myCtrl', ['$scope', function($scope) { | |
$scope.MyProccessedData = ""; | |
}]) | |
.directive('myDirective', [function(){ | |
return function(scope, element, attrs) { | |
element.bind('keydown', function(event) { | |
scope.MyProccessedData = scope.$eval(attrs.ngModel); | |
}); | |
}; | |
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.min.js"></script> | |
<script src="app.js"></script> | |
<meta charset=utf-8 /> | |
<title>Watching my input</title> | |
</head> | |
<body data-ng-app="myApp" data-ng-controller="myCtrl"> | |
<label> | |
Type something here: | |
<input type="text" data-ng-model="myModel" data-my-directive /> | |
</label> | |
<p>{{input}}</p> | |
<p>Unprocessed data: {{myModel}}</p> | |
<p>Processed data: {{MyProccessedData}}</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment