Last active
August 18, 2016 10:04
-
-
Save mhgbrown/0b7d482ee369c0a4efd062976f82e34b to your computer and use it in GitHub Desktop.
ES6 Class-based Angular 1.x ngError Directive: could be more "ES6-y", but you get the gist π
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
class ngError { | |
constructor($parse) { | |
this.$parse = $parse; | |
this.restrict = 'A'; | |
} | |
link(scope, $element, attrs) { | |
var onError = this.$parse(attrs['ngError']); | |
$element.on('error', function(event) { | |
scope.$apply(function() { | |
onError(scope, { $event: event }); | |
}); | |
}); | |
} | |
static createInstance ($parse) { | |
return new ngError($parse); | |
} | |
} | |
ngError.createInstance.$inject = ['$parse']; | |
export default ngError; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment