I'm trying to build a simple directive following the tutorial from this link: http://slides.com/djsmith/deep-dive-into-custom-directives (it's slides 11 and 12 I think, there is no numbering).
Since it just shows the JavaScript part and small part of the HTML part (just the text input). I made my own html page as follows:
<!DOCTYPE html>
<html>
<head>
<title>Directives</title>
<script src="Scripts/angular.min.js"></script>
<script src="Scripts/angular-route.min.js"></script>
<script src="Scripts/app.js"></script>
</head>
<body ng-app="MyDirectives" ng-controller="DirectivesController">
<input type="text" select-all-on-focus />
</body>
</html>
The JS file with the module and the controller (just an empty one, I thought not having one might be the problem) and the directive:
var myModule = angular.module('MyDirectives', []);
myModule.controller('DirectivesController', ['$scope', function ($scope) {
}]);
myModule.directive('selectAllOnFocus', function () {
return {
restrict: 'A',
link: function linkFn (scope, element, attrs) {
element.mouseup(function (event) {
alert("Lost focus!");
event.preventDefault();
});
element.focus(function () {
element.select();
alert("Focused!");
});
}
}
});
The error which appears on the Chrome console is:
TypeError: undefined is not a function at linkFn at J at f at J at f at ... at ... at h.$get.h.$eval at h.$get.h.$apply at http://
There seems to be a problem with the link function.
link: function(scope, element, attrs)will domouseupby any chance?