Created
April 15, 2016 09:35
-
-
Save esaiz/1bf0236e92b0dea9d5906b9a8d81a860 to your computer and use it in GitHub Desktop.
Example of directive with ng-forward
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
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