I'm just starting to learn angular and I've run into a problem with the scope in my directive and controller. Take a look at my code:
Controller:
var myApp = angular.module('myApp', []);
myApp.controller('testCtrl', function ($scope, $http) {
$scope.doSomething = function() {
alert("Testing Scope");
};
});
Directive:
myApp.directive('keyEvents', function($document) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
$document.on('keypress', function(e) {
switch (e.keyCode) {
case (49):
doSomething();
break
default:
}
});
}
};
});
HTML:
<script src= "js/main.js"></script>
<script src = "js/keyevents.js"></script>
<body ng-app ="myApp">
<div ng-controller="testCtrl">
<div key-events>
</div>
</div>
</body>
I keep getting this error: Uncaught ReferenceError: doSomething is not defined - how can I access the doSomething function within my directive?