Skip to content

Instantly share code, notes, and snippets.

@mhgbrown
Last active August 18, 2016 10:04
Show Gist options
  • Save mhgbrown/0b7d482ee369c0a4efd062976f82e34b to your computer and use it in GitHub Desktop.
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 πŸ˜‰
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