Created
September 29, 2015 16:58
-
-
Save seangwright/95d59bee746d8ae7e111 to your computer and use it in GitHub Desktop.
ES2015 Angular directive definition with ngAnnotate annotation & ES2015 module format
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
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