Skip to content

Instantly share code, notes, and snippets.

@seangwright
Created September 29, 2015 16:58
Show Gist options
  • Save seangwright/95d59bee746d8ae7e111 to your computer and use it in GitHub Desktop.
Save seangwright/95d59bee746d8ae7e111 to your computer and use it in GitHub Desktop.
ES2015 Angular directive definition with ngAnnotate annotation & ES2015 module format
function appCompareTo(serviceOne, serviceTwo) {
'ngInject'; // Note position of 'ngInject' annotation
return {
require: "ngModel",
scope: {
otherModelValue: "=appCompareTo"
},
link: link
};
function link(scope, element, attributes, ngModel) {
ngModel.$validators.appCompareTo = function(modelValue) {
serviceOne.methodA();
serviceTwo.methodB();
return modelValue == scope.otherModelValue;
};
scope.$watch("otherModelValue", function() {
ngModel.$validate();
});
}
}
export default { directive: appCompareTo, name: 'appCompareTo' };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment