1.指令内容
myApp.directive('ngKeydown', function() {
return {
restrict: 'A',
link: function(scope, elem, attrs) {
// this next line will convert the string
// function name into an actual function
var functionToCall = scope.$eval(attrs.ngKeydown);
//console.log(attrs.ngKeydown)
elem.on('keydown', function(e){
functionToCall(e);
});
}
};
});
2.指令的使用
ng-keydown="keyUpNumber"
//$scope.keyUpNumber = function(){}