Skip to content

Instantly share code, notes, and snippets.

@brysgo
Forked from nl5887/ng_initial.js
Last active August 29, 2015 13:57
Show Gist options
  • Save brysgo/9686420 to your computer and use it in GitHub Desktop.
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.
@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