Skip to content

Instantly share code, notes, and snippets.

@esaiz
Created April 15, 2016 09:35
Show Gist options
  • Save esaiz/1bf0236e92b0dea9d5906b9a8d81a860 to your computer and use it in GitHub Desktop.
Save esaiz/1bf0236e92b0dea9d5906b9a8d81a860 to your computer and use it in GitHub Desktop.
Example of directive with ng-forward
import { Directive, Inject } from 'ng-forward';
@Directive({
selector: '[value-to-check]',
})
@Inject('$scope', '$attrs', 'ngModel')
export default class CheckEqual {
constructor($scope, $attrs, ngModel) {
// Add functionality to check the value when the model value changes
ngModel.$validators.equal = value => $scope.$eval($attrs.valueToCheck) === value;
$scope.$watch($attrs.valueToCheck, () => {
ngModel.$validate();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment