-
-
Save brysgo/9686420 to your computer and use it in GitHub Desktop.
Directive to use the value of the DOM element as the default for an ngModel instead of having to bootstrap from the controller.
This file contains hidden or 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
@app.directive 'ngUseDefault', -> | |
restrict: 'A' | |
controller: ['$scope', '$element', '$attrs', '$parse', ($scope, $element, $attrs, $parse) -> | |
initialValue = $element.val() | |
getter = $parse($attrs.ngModel) | |
setter = getter.assign | |
setter($scope, initialValue) | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment